How to use the q.isPromise function in q

To help you get started, we’ve selected a few q 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 bahmutov / xplain / test / as-package.js View on Github external
it('returns a promise', function () {
    var testFolder = path.join(__dirname, '../examples/jasmine-module');
    var p = xplain.document({
      patterns: testFolder + '/sp*.js',
      outputFolder: testFolder + '/docs',
      title: 'as module works'
    });
    lazyAss(Q.isPromise(p));
    return p.done();
  });
github jaystack / jaydata / test / qunit / scripts / NodeJS / commonTests.js View on Github external
context.onReady(function(){
            var promise = context.Items.toArray();
            var q = require('q');
            
            test.equal(q.isPromise(new $data.PromiseHandlerBase().getPromise()), false, '$data.PromiseHandlerBase returns Q promise failed!');
            test.equal(q.isPromise(promise), true, '$data.PromiseHandler returns Q promise failed!' + promise);

            test.done();
        });
    },
github kriskowal / q-http / test / basic.js View on Github external
.then(function (response) {
            ASSERT.ok(!Q.isPromise(response.body), "body is not a promise")
            var acc = [];
            return response.body.forEach(function (chunk) {
                acc.push(chunk.toString("utf-8"));
            }).then(function () {
                ASSERT.equal(acc.join(""), "Hello, World!", "body is hello world");
            });
        })
    })
github sskyy / twenty / api / services / ModelService.js View on Github external
sails.emit("hook:"+name+":"+hook,v, function gatherListenerResult( result ){
          if(q.isPromise( result) ){
            _promises.push(result)
          }
        })
        if( _promises.length == 0 ){
github SLaks / Qx / Qx.js View on Github external
function eagerWhen(valueOrPromise, callback) {
	if (Q.isPromise(valueOrPromise))
		return valueOrPromise.then(callback);
	else
		return callback(valueOrPromise);
}
github zuudo / helios.js / lib / q-comm.js View on Github external
function encode(object) {
        if (Q.isPromise(object)) {
            var id = makeId();
            makeLocal(id);
            resolveLocal(id, object);
            return {"@": id};
        } else if (Array.isArray(object)) {
            return object.map(encode);
        } else if (typeof object === "object") {
            var result = {};
            for (var key in object) {
                if (has.call(object, key)) {
                    var newKey = key;
                    if (/^[!@]$/.exec(key))
                        newKey = key + key;
                    result[newKey] = encode(object[key]);
                }
            }
github allcount / allcountjs / services / app-util.js View on Github external
var result;
            if (_.isFunction(object)) {
                result = self.evaluateObject(injection.resolveFuncArgs(object, function (dependency) {
                    if (dependency === '$parentProperty') {
                        return parent && name && self.evaluateObject(parent[name], parent.__proto__, name).obj;
                    } else {
                        return injection.lookup(dependency);
                    }
                }));
            } else if (_.isArray(object)) {
                result = object.map(function (i) {
                    return self.evaluateObject(i)
                });
            } else if (_.isDate(object)) {
                return object;
            } else if (Q.isPromise(object) || object && object.then) {
                result = Q(object); //TODO .then(evaluateObject) ?
            } else if (_.isObject(object)) {
                result = new self.ConfigObject(object);
            } else {
                result = object;
            }
            return result;
        }
    };
github kriskowal / q-io / spec / http / basic-spec.js View on Github external
.then(function (response) {
                expect(Q.isPromise(response.body)).toBe(false);
                var acc = [];
                return response.body.read()
                .then(function (body) {
                    expect(body.toString("utf-8")).toBe("Hello, World!");
                });
            })
        })
github johnjbarton / Purple / lib / MetaObject / q-comm / q-comm.js View on Github external
function encode(object) {
        if (Q.isPromise(object)) {
            var id = makeId();
            makeLocal(id);
            resolveLocal(id, object);
            return {"@": id};
        } else if (Array.isArray(object)) {
            return object.map(encode);
        } else if (typeof object === "object") {
            var result = {};
            for (var key in object) {
                if (has.call(object, key)) {
                    var newKey = key;
                    if (/^[!@]$/.exec(key))
                        newKey = key + key;
                    result[newKey] = encode(object[key]);
                }
            }
github kriskowal / q-connection / q-connection.js View on Github external
} else if (object === Number.NEGATIVE_INFINITY) {
                    return {"%": "-Infinity"};
                } else if (isNaN(object)) {
                    return {"%": "NaN"};
                }
            }
            return object;
        } else {
            var id;
            if (memo.has(object)) {
                return {"$": memo.get(object)};
            } else {
                memo.set(object, path);
            }

            if (Q.isPromise(object) || typeof object === "function") {
                id = makeId();
                makeLocal(id);
                dispatchLocal(id, "resolve", object);
                return {"@": id, "type": typeof object};
            } else if (Array.isArray(object)) {
                return object.map(function (value, index) {
                    return encode(value, memo, path + "/" + index);
                });
            } else if (
                (
                    object.constructor === Object &&
                    Object.getPrototypeOf(object) === Object.prototype
                ) ||
                object instanceof Error
            ) {
                var result = {};