How to use the when.promise function in when

To help you get started, we’ve selected a few when 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 rkaw92 / esdf / utils / tryWith.js View on Github external
function delay(continuation) {
		return when.promise(function(resolve){
			delegationFunction(resolve);
		}).then(continuation);
	}
	// Allow the caller to specify a failure logger function, to which all intermediate errors will be passed.
github xat / chromecast-player / chromecast-player.js View on Github external
var findDevice = function(deviceName, ttl) {
  return promise(function(resolve, reject) {
    var scanner = mdns.createBrowser(mdns.tcp('googlecast'));
    if (!ttl) ttl = 10000; // default to 10 seconds
    var timer = setTimeout(function() {
      scanner.stop();
      reject('device not found');
    }, ttl);
    scanner.on('serviceUp', function(service) {
      if (deviceName && deviceName !== service.name) return;
      resolve(service);
      scanner.stop();
      clearTimeout(timer);
    });
    scanner.start();
  });
};
github jstty / hyper.io / lib / service.middleware / apiviewRoutes.js View on Github external
_loadView (service, route, routeStr) {
    // add promise wrapper
    return when.promise(function (resolve, reject) {
    // ------------------------------------------------
      var templateMiddleware, templateDefaultMW;

      if (!route.hasOwnProperty('template')) {
        service.logger.warn('Template missing from route view', routeStr);
        return;
      }

      // get all 'template' middleware
      templateMiddleware = this._middleware.getAll('template');
      templateDefaultMW = this._middleware.getDefault('template');
      if (!Object.keys(templateMiddleware).length || !templateDefaultMW) {
        // load default templates
        this._middleware.install([{
          group:   'template',
          name:    'ejs',
github joeferner / node-java / testAsyncOptions / testNoAsync.js View on Github external
function after() {
      var promise = when.promise(function(resolve, reject) {
        test.ok(java.isJvmCreated());
        resolve();
      });
      return promise;
    }
github joeferner / node-java / testAsyncOptions / testNoAsync.js View on Github external
function before() {
      var promise = when.promise(function(resolve, reject) {
        test.ok(!java.isJvmCreated());
        resolve();
      });
      return promise;
    }
github WEBdeBS / webdebs-links / src / utils / api.js View on Github external
export function getLinks(page) {
  return promise((resolve, reject) => {
    request.get(`${url}${page}`).end((err, res) => {
      if (err) {
        reject(err);
      } else {
        resolve(JSON.parse(res.text));
      }
    });
  });
}
github gregturn / spring-a-gram / spring-a-gram-frontend / src / main / resources / static / app / imageShrinker.js View on Github external
function shrink(image, maxWidth, maxHeight) {
		return when.promise(function(resolve, reject) {
			var canvas = document.createElement('canvas');
			var img = new Image();
			img.onload = function() {
				var MAX_WIDTH = maxWidth;
				var MAX_HEIGHT = maxHeight;
				var width = img.width;
				var height = img.height;

				if (width > height) {
					if (width > MAX_WIDTH) {
						height *= MAX_WIDTH / width;
						width = MAX_WIDTH;
					}
				} else {
					if (height > MAX_HEIGHT) {
						width *= MAX_HEIGHT / height;
github EdgeVerve / oe-cloud / lib / db-storage-for-node-red.js View on Github external
function writeFile(path, content) {
  return when.promise(function writeFilePromiseFn(resolve, reject) {
    var stream = fs.createWriteStream(path);
    stream.on('open', function writeFileStreamOpenFn(fd) {
      stream.end(content, 'utf8', function writeFileStreamEndFn() {
        fs.fsync(fd, resolve);
      });
    });
    stream.on('error', function writeFileStreamErrorFn(err) {
      reject(err);
    });
  });
}
github jacobrosenthal / usbtinyisp / examples / attiny85.js View on Github external
function setSCK(){
      return when.promise(function(resolve, reject) {
        tinyAVR.setSCK(function(err){
          if(err){ return reject(err); }
          return resolve();
        });
      });
    }
github scottnonnenberg / dangerous-cliffs-of-nodejs / src / demos / 4. Error from async call / c. promises via when.js View on Github external
var callRemoteService = function callRemoteService() {
  return when.promise(function(resolve, reject) {
    setTimeout(function() {
      if (_.random(0, 10) < 3) {
        return reject(new Error('Incorrect arguments supplied'));
      }
      return resolve();
    });
  });
};