How to use the when.isPromiseLike 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 particle-iot / spark-cli / lib / interpreter.js View on Github external
handle: function (args, shouldExit) {
		var result;

		if (!args || args.length == 2) {
			result = this.runCommand("help");
		}
		else if (args.length >= 2) {
			result = this.runCommand(args[2], args.slice(3));
		}

		if (when.isPromiseLike(result)) {
			when(result).catch(function(err) {
				if (shouldExit) {
					process.exit(1);
				}
			});
		}
		else {
			return result;
		}
//        else {
//            if (shouldExit) {
//                process.exit(parseInt(result));
//            }
//            else {
//                return result;
//            }
github jstty / hyper.io / lib / service.middleware / apiviewRoutes.js View on Github external
error({ error: err.message });
    }

    // if function is generator then wait on yield
    if (util.isES6Function(handlerFunc)) {
      try {
        // result is generator, so co wrapper it and turn into promise
        result = co(result);
      }
      catch (err) {
        error({ error: err.message });
      }
    }

    // if result is promise, fire done on the result data
    if (when.isPromiseLike(result)) {
      result.then(function (output) {
        // TODO: figure out better way to handle combined input/vs just data
        // API breaking change?
        if (output && output.data && output.code) {
          done(output.data, output.code, output.headers);
        }
        else {
          done(output);
        }
      })
      .catch(function (err) {
        error({ error: err });
      });
    }
    // if result is not promise and not null or undefined
    else if (_.isObject(result) && result.data && result.code) {
github cujojs / cola / adapter / Object.js View on Github external
ObjectAdapter.canHandle = function (obj) {
		// this seems close enough to ensure that instanceof works.
		// a RegExp will pass as a valid prototype, but I am not sure
		// this is a bad thing even if it is unusual.
		// IMPORTANT: since promises *are* objects, the check for isPromise
		// must come first in the OR
		return obj && (when.isPromiseLike(obj) || Object.prototype.toString.call(obj) == '[object Object]');
	};
github trayio / falafel / test / bindConnectors / bindTriggerRequest.js View on Github external
request: function () {}
			},
			devOptions
		);

		var returnedPromise = requestFunc({
			body: {
				input: {},
				http: {
					headers: {},
					body: '{}'
				}
			}
		});

		assert(when.isPromiseLike(returnedPromise));


		var requestFunc2 = bindTriggerRequest(
			{
				request: {}
			},
			devOptions
		);

		var returnedPromise2 = requestFunc2({
			body: {
				input: {},
				http: {
					headers: {},
					body: '{}'
				}
github brianc / node-pg-query / test / index.js View on Github external
var noPromise = query('SELECT NOW() as when', function(err, rows, result) {
        if(err) return done(err);
        assert(!when.isPromiseLike(noPromise));
        assert(util.isArray(rows));
        assert.equal(rows.length, 1);
        assert.equal(rows, result.rows);
        done();
      });
    });
github pwagener / backbone.conduit / spec / browser / WorkerManager.browserSpec.js View on Github external
it('should provide a promise from "runJob"', function() {
        var returned = boundRunJob();
        expect(when.isPromiseLike(returned)).to.equal(true);
    });
github pwagener / backbone.conduit / spec / browser / _Worker.browserSpec.js View on Github external
it('should return a promise from "sort"', function() {
                //noinspection BadExpressionStatementJS,JSUnresolvedFunction,JSUnresolvedVariable
                expect(when.isPromiseLike(promise)).to.be.true;
            });
github pwagener / backbone.conduit / spec / worker / data / load.spec.js View on Github external
it('returns a promise', function() {
            expect(when.isPromiseLike(promise)).to.be.true;
        });
github pwagener / backbone.conduit / spec / browser / config.browserSpec.js View on Github external
it('returns a promise from "enableWorker"', function() {
        var enablePromise = config.enableWorker();
        expect(when.isPromiseLike(enablePromise));

        enablePromise.done(noop, noop);
    });
github particle-iot / particle-cli / src / lib / interpreter.js View on Github external
handle(args, shouldExit) {
		let result;

		if (!args || args.length === 2) {
			result = this.runCommand('help');
		} else if (args.length >= 2) {
			result = this.runCommand(args[2], args.slice(3));
		}

		if (when.isPromiseLike(result)) {
			result.done((res) => {
				process.exit(+res || 0);
			}, () => {
				if (shouldExit) {
					process.exit(1);
				}
			});
		} else {
			if (result !== undefined) {
				process.exit(result === 0 ? 0 : 1);
				return;
			}
		}
	}