How to use the bluebird.method function in bluebird

To help you get started, we’ve selected a few bluebird 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 wikimedia / html-metadata / lib / index.js View on Github external
}
	if (!Object.keys(metadata).length){
		return BBPromise.reject(Error('No COinS in provided string'));
	}
	if (metadata.rft && metadata.rft.genre){
		metadata.rft.genre = metadata.rft.genre.toLowerCase(); // Genre should be case insensitive as this field may be used programmatically
	}
	return metadata;
});

/**
 * Scrapes Dublin Core data given Cheerio loaded html object
 * @param  {Object}   chtml html Cheerio object
 * @return {Object}         BBPromise for DC metadata
 */
exports.parseDublinCore = BBPromise.method(function(chtml){

	return exports.parseBase(
		chtml,
		['meta', 'link'],
		'No Dublin Core metadata found in page',
		function(element) {
			var isLink = element[0].name === 'link';
			var nameAttr = element.attr(isLink ? 'rel' : 'name');
			var value = element.attr(isLink ? 'href' : 'content');

			// If the element isn't a Dublin Core property or if value is missing, skip it
			if (!nameAttr || !value
				|| (nameAttr.substring(0, 3).toUpperCase() !== 'DC.'
					&& nameAttr.substring(0, 8).toUpperCase() !== 'DCTERMS.')) {
				return;
			}
github wikimedia / html-metadata / lib / index.js View on Github external
// Reject promise if meta is empty
	if (Object.keys(meta).length === 0){
		throw new Error('No general metadata found in page');
	}

	// Resolve on meta
	return meta;
});

/**
 * Scrapes Highwire Press metadata given html object
 * @param  {Object}   chtml html Cheerio object
 * @return {Object}   promise of highwire press metadata object
 */
exports.parseHighwirePress = BBPromise.method(function(chtml){

	return exports.parseBase(
		chtml,
		['meta'],
		'No Highwire Press metadata found in page',
		function(element) {
			var nameAttr = element.attr('name');
			var content = element.attr('content');

			// If the element isn't a Highwire Press property, skip it
			if (!nameAttr || !content || (nameAttr.substring(0, 9).toLowerCase() !== 'citation_')) {
				return;
			}

			return nameAttr.substring(nameAttr.indexOf('_') + 1).toLowerCase();
		},
github alanhoff / node-portastic / test / fixtures / helpers.js View on Github external
debug('Server TCP at port %s has stopped', number);
        def.resolve();
      });

      server.listen(number, iface, function(err) {
        if (err)
          def.reject(err);

        def.resolve(server);
      });

      return def.promise;
    });
});

exports.stopTcp = bluebird.method(function(arr) {
  return bluebird.resolve([].concat(arr))
    .each(function(server) {
      var def = bluebird.defer();
      server.close(def.callback);

      return def.promise;
    });

});

exports.autoClose = bluebird.method(function(ports, iface, promise) {
  if (!promise || typeof iface !== 'string') {
    promise = iface;
    iface = null;
  }
github gitterHQ / halley / test / helpers / bayeux-with-proxy-server.js View on Github external
if (err) return callback(err);
      self.bayeuxServer.stop(function(err) {

        if (err) return callback(err);
        callback();
      });
    });

  },

  networkOutage: Promise.method(function(timeout) {
    this.proxyServer.disableTraffic(timeout);
  }),

  stopWebsockets: Promise.method(function(timeout) {
    this.bayeuxServer.crush(timeout);
  }),

  deleteSocket: Promise.method(function(clientId) {
    return Promise.fromCallback(this.bayeuxServer.deleteClient.bind(this.bayeuxServer, clientId));
  }),

  restart: Promise.method(function() {
    var proxy = this.proxyServer;
    return Promise.fromCallback(proxy.stop.bind(proxy))
      .delay(500)
      .then(function() {
        return Promise.fromCallback(proxy.start.bind(proxy));
      });
  }),
github colonyamerican / mock-knex / lib / platforms / knex / 0.8 / client.js View on Github external
function mockClient(client) {
  client.driverName = 'mocked';

  client.acquireConnection = Promise.method(function() {
    return connection;
  });

  client.releaseConnection = Promise.method(_.noop);

  client.acquireRawConnection = Promise.method(function() {
    return {};
  });

  client.destroyRawConnection = function destroyRawConnection(connection, cb) {
    cb();
  };

  client.constructor.prototype._query = client._query = function(connection, obj) {
    return new Promise(function(resolver, rejecter) {
      tracker.queries.track(obj, resolver);
    });
  };

  client.constructor.prototype.processResponse = client.processResponse = function(obj) {
github chiefy / vaulted / lib / auth / token.js View on Github external
headers: this.headers,
      _token: options.token
    });
});

/**
 * @method revokeTokenSelf
 * @desc Revokes the current client token and all child tokens.
 *
 * @param {string} [options.token] - the authentication token
 * @param {string} [mountName=token] - path name the token auth backend is mounted on
 * @resolve success
 * @reject {Error} An error indicating what went wrong
 * @return {Promise}
 */
Vaulted.revokeTokenSelf = Promise.method(function revokeTokenSelf(options, mountName) {
  options = options || {};

  return this.getTokenRevokeSelfEndpoint(mountName)
    .post({
      headers: this.headers,
      _token: options.token
    });
});
github OADA / oada-formats / model.js View on Github external
return null;
});

/**
 * Returns all examples
 * @returns {object}
 */
Model.prototype.examples = Promise.method(function examples() {
    return _.clone(this._examples);
});

/**
 * Returns schema
 * @returns {object}
 */
Model.prototype.schema = Promise.method(function schema() {
    return _.clone(this._schema);
});
github plediii / route53-controller / bin / createPolicy.js View on Github external
return new Promise(function (resolve, reject) {
        return iam.createPolicy({
            PolicyDocument: document
            , PolicyName: name
            , Description: description
        }, function (err, data) {
            if (err) {
                return reject(err);
            } else {
                return resolve(data);
            }
        });
    });
});

var putUserPolicy = Promise.method(function (iam, user, document, name) {
    return new Promise(function (resolve, reject) {
        return iam.putUserPolicy({
            PolicyDocument: document
            , PolicyName: name
            , UserName: user
        }, function (err, data) {
            if (err) {
                return reject(err);
            } else {
                return resolve(data);
            }
        });
    });
});

var putRolePolicy = Promise.method(function (iam, role, document, name) {
github colonyamerican / fluxApp / src / dispatcher.js View on Github external
register(callback, events = '*') {
    const id = _prefix + _lastID;

    events = _.isString(events) ? [ events ] : events;

    if (! _.size(events)) {
      throw new Error('Fluxapp: Dispatcher requires a list of events or "*" to receive all events');
    }

    this._callbacks[id] = Promise.method(callback);

    _.each(events, (event) => {
      event = event === '*' ? event : namespaceTransform(event);
      this._events[event] = this._events[event] || [];
      this._events[event].push(id);
    });

    _lastID += 1;

    return id;
  }
github auth0 / webtask-widget / src / lib / widget.js View on Github external
const flushNext = (ret) => {
            if (!this._queue.length) return Bluebird.resolve(ret);
            
            const { method, args, dfd } = this._queue.shift();
            const invocation = Bluebird.method(this.component[method]);
            const promise = invocation.apply(this.component, args);
            
            dfd.resolve(promise);
            
            return promise
                .then(flushNext);
        };