How to use the promise.from function in promise

To help you get started, we’ve selected a few promise examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ForbesLindesay / pull-request / index.js View on Github external
function commit(user, repo, commit, options, callback) {
  var branch = commit.branch || 'master'
  var message = commit.message
  var updates = commit.updates
  var shaLatestCommit, shaBaseTree, shaNewTree, shaNewCommit

  return Promise.from(null).then(function () {

    //check for correct input
    assert(user && typeof user === 'string', '`user` must be a string')
    assert(repo && typeof repo === 'string', '`repo` must be a string')
    assert(branch && typeof branch === 'string', '`branch` must be a string')
    assert(message && typeof message === 'string', '`message` must be a string')

    updates = Promise.all(updates.map(function (file) {
      // {path: string, content: string|Buffer}
      assert(typeof file.path === 'string', '`file.path` must be a string')
      assert(typeof file.content === 'string' || Buffer.isBuffer(file.content), '`file.content` must be a string or a Buffer')
      var path = file.path.replace(/\\/g, '/').replace(/^\//, '')
      var mode = file.mode || '100644'
      var type = file.type || 'blob'
      return github.json('post', '/repos/:owner/:repo/git/blobs', {
        owner: user,
github taskcluster / taskcluster / services / auth / routes / client.js View on Github external
exports.update = function(req, res) {
  debug("Create/update client: %j", req.body);
  var Client = req.app.globals.Client;
  Promise.from(null).then(function() {
    // Create client if requested
    if (req.body.updateOrCreate == 'create') {
      return Client.create({
        version:        '0.2.0',
        name:           req.body.name,
        clientId:       slugid.v4(),
        accessToken:    slugid.v4() + slugid.v4() + slugid.v4(),
        scopes:         JSON.parse(req.body.scopes),
        expires:        new Date(req.body.expires),
        details: {
          notes:        req.body.notes
        }
      });
    }

    // Update WorkerType if requested
github taskcluster / taskcluster / libraries / app / entity.js View on Github external
var retryLoop = function() {
    // Apply modifier to properties
    var modified = Promise.from(modifier.call(properties));

    // When modified attempt to update
    return modified.then(function() {
      var updated = attemptUpdate();

      // If update fails we retry it gain
      return updated.catch(function(err) {
        // Rethrow error, if this didn't happen because of an etag mismatch
        if (err.code != 'UpdateConditionNotSatisfied') {
          debug(
            "Update of entity failed unexpectedly, %s, as JSON: %j",
            err, err, err.stack
          );
          throw err;
        }
github taskcluster / taskcluster / services / auth / auth / data.js View on Github external
var retryLoop = function() {
    // Apply modifier to properties
    var modified = Promise.from(modifier.call(properties));

    // When modified attempt to update
    return modified.then(function() {
      var updated = attemptUpdate();

      // If update fails we retry it gain
      return updated.catch(function(err) {
        // Rethrow error, if this didn't happen because of an etag mismatch
        if (err.code != 'UpdateConditionNotSatisfied') {
          debug(
            "Update of entity failed unexpectedly, %s, as JSON: %j",
            err, err, err.stack
          );
          throw err;
        }
github nodekit-io / nodekit-darwin / src / app-shared / owinjs / owinAppBuilder.js View on Github external
try {
            return fn(owin).then(function(){
                                    if (expand) { owinContext.shrinkContext(owin); }
                                    owin = null;
                                },
                                    function(err){
                                    owinDefaultError.call(owin, err);
                                    if (expand) { owinContext.shrinkContext(owin); }
                                });
        }
        catch (err)
        {
            owinDefaultError.call(owin,err);
            if (expand) { owinContext.shrinkContext(owin); }
            return Promise.from(null);
        }
    };
};
github nodekit-io / nodekit-darwin / src / app-shared / owinjs / owinAppBuilder.js View on Github external
        prev = function (){return Promise.from(null);};
        while (i--) {
github taskcluster / taskcluster / services / auth / node_modules / taskcluster-base / api.js View on Github external
return function(req, res) {
    Promise.from().then(function() {
      return handler.call(context, req, res);
    }).catch(function(err) {
      var incidentId = uuid.v4();
      debug(
        "Error occurred handling: %s, err: %s, as JSON: %j, incidentId: %s",
        req.url, err, err, incidentId, err.stack
      );
      res.json(500, {
        message:        "Internal Server Error",
        error: {
          info:         "Ask administrator to lookup incidentId in log-file",
          incidentId:   incidentId
        }
      });
    });
  };
github nodekit-io / nodekit-darwin / src / app-shared / owinjs / owinAppBuilder.js View on Github external
function owinDefaultApp(next){
    if (this[constants.owinjs.Error])
    {
        return Promise.reject(this[constants.owinjs.Error]);
    }
    else if (this.response.statusCode === null)
    {
        return Promise.reject(404);
    }
    else
    {
        return Promise.from(null);
    }
}
github taskcluster / taskcluster / services / auth / routes / api / utils.js View on Github external
options.handler = function(req, res) {
    Promise.from(handler(req, res)).then(undefined, function(err) {
      var incidentId = uuid.v4();
      debug(
        "Error occurred handling: %s, err: %s, as JSON: %j, incidentId: %s",
        options.route, err, err, incidentId, err.stack
      );
      res.json(500, {
        message:        "Internal Server Error",
        error: {
          info:         "Ask administrator to lookup incidentId in log-file",
          incidentId:   incidentId
        }
      });
    });
  };
github taskcluster / taskcluster / services / queue / routes / api / utils.js View on Github external
options.handler = function(req, res) {
    Promise.from(handler(req, res)).catch(function(err) {
      var incidentId = uuid.v4();
      debug(
        "Error occurred handling: %s, err: %s, as JSON: %j, incidentId: %s",
        options.route, err, err, incidentId, err.stack
      );
      res.json(500, {
        message:        "Internal Server Error",
        error: {
          info:         "Ask administrator to lookup incidentId in log-file",
          incidentId:   incidentId
        }
      });
    });
  };