How to use the q.when 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 kriskowal / lode / lib / fs.js View on Github external
};
                        });
                    });
                }
                // TODO tar tar.gz tgz
            }
            return {
                "fs": fs,
                "http": http,
                "path": path,
                "href": baseUrl + path
            };
        });
    } else if (/^https?:$/.test(parsed.protocol)) {
        url = URL.resolve(baseUrl, url);
        return Q.when(http.read(url), function (data) {
            var fs = Zip(data);
            return Q.when(fs, function (fs) {
                return {
                    "fs": fs,
                    "http": http,
                    "path": "/",
                    "href": url + "#/"
                };
            });
        });
    } else {
        throw new Error("Cannot fetch over protocol " + parsed.protocol + " (" + url + ")");
    }
}
github alex-shpak / keemob / platforms / android / cordova / lib / emulator.js View on Github external
}).then(function () {
        // This promise is always resolved, even if 'adb uninstall' fails to uninstall app
        // or the app doesn't installed at all, so no error catching needed.
        return Q.when().then(function () {

            var apk_path = build.findBestApkForArchitecture(buildResults, target.arch);
            var execOptions = {
                cwd: os.tmpdir(),
                timeout: INSTALL_COMMAND_TIMEOUT, // in milliseconds
                killSignal: EXEC_KILL_SIGNAL
            };

            events.emit('log', 'Using apk: ' + apk_path);
            events.emit('log', 'Package name: ' + pkgName);
            events.emit('verbose', 'Installing app on emulator...');

            // A special function to call adb install in specific environment w/ specific options.
            // Introduced as a part of fix for http://issues.apache.org/jira/browse/CB-9119
            // to workaround sporadic emulator hangs
            function adbInstallWithOptions (target, apk, opts) {
github blocktrail / wallet-recovery-tool / src / libs / blocktrail-sdk / lib / wallet.js View on Github external
deferred.resolve(q.fcall(function() {
        return q.when()
            .then(function() {
                /* jshint -W071, -W074 */
                options.encryptedPrimarySeed = typeof options.encryptedPrimarySeed !== "undefined" ? options.encryptedPrimarySeed : self.encryptedPrimarySeed;
                options.encryptedSecret = typeof options.encryptedSecret !== "undefined" ? options.encryptedSecret : self.encryptedSecret;

                if (options.secret) {
                    self.secret = options.secret;
                }

                if (options.primaryPrivateKey) {
                    throw new blocktrail.WalletInitError("specifying primaryPrivateKey has been deprecated");
                }

                if (options.primarySeed) {
                    self.primarySeed = options.primarySeed;
                } else if (options.secret) {
github kriskowal / q-fs / common.js View on Github external
return Q.when(list, function (list) {
                    // asynchronously remove every subtree
                    var done = list.reduce(function (prev, name) {
                        var child = self.join(path, name);
                        var next = self.removeTree(child);
                        // join next and prev
                        return Q.when(prev, function () {
                            return next;
                        });
                    });
                    return Q.when(done, function () {
                        self.removeDirectory(path);
                    });
                });
            } else {
github blocktrail / blocktrail-sdk-nodejs / lib / wallet.js View on Github external
deferred.resolve(q.fcall(function() {
        return q.when()
            .then(function() {
                /* jshint -W071, -W074 */
                options.encryptedPrimarySeed = typeof options.encryptedPrimarySeed !== "undefined" ? options.encryptedPrimarySeed : self.encryptedPrimarySeed;
                options.encryptedSecret = typeof options.encryptedSecret !== "undefined" ? options.encryptedSecret : self.encryptedSecret;

                if (options.secret) {
                    self.secret = options.secret;
                }

                if (options.primaryPrivateKey) {
                    throw new blocktrail.WalletInitError("specifying primaryPrivateKey has been deprecated");
                }

                if (options.primarySeed) {
                    self.primarySeed = options.primarySeed;
                } else if (options.secret) {
github SLaks / Qx / test / Qx-tests.js View on Github external
*/
	function createFunctionArray(arr) {
		return arr.map(function (item, actualIndex) {
			return function (index) {
				assert.strictEqual(actualIndex, index, "Function-array call passed wrong index to callback");
				return Q.when(item, function (result) { return callback(result, index); });
			};
		});
	}

	return Q.all([
		//method(array, callback)
		method(arrayFunc(), callback).then(resultFunc, errorFunc),

		//method(callback)
		Q.when(arrayFunc()).then(method(callback)).then(resultFunc, errorFunc),

		//method(funcArray)
		noFunctions || method(Q.when(arrayFunc(), createFunctionArray)).then(resultFunc, errorFunc),

		//method()
		noFunctions || Q.when(arrayFunc(), createFunctionArray).then(method).then(resultFunc, errorFunc)
	]);
}
github kriskowal / q-io / fs-root.js View on Github external
return attenuate(path).then(function (path) {
            return outer.makeTree(path.outer);
        }).catch(function (error) {
            throw new Error("Can't make tree " + JSON.stringify(path));
        });
    };

    inner.removeTree = function (path) {
        return attenuate(path).then(function (path) {
            return outer.removeTree(path.outer);
        }).catch(function (error) {
            throw new Error("Can't remove tree " + JSON.stringify(path));
        });
    };

    return Q.when(outer.canonical(root), function (_root) {
        root = _root;
        return inner;
    });
}
github martijndeh / fire / examples / multiple-apps / .fire / api / app1 / shared.js View on Github external
credentials = null;
		}
		else if(credentials.length == 1) {
			credentials.push('');
		}
	}

	if(credentials) {
		var findMap = {};
		findMap[authenticatorModel.options.authenticatingProperty.name] = credentials[0];
		findMap.accessToken = credentials[1];
		return authenticatorModel.findOne(findMap);
	}

	if(!request.session.at) {
		return Q.when(null);
	}

	return authenticatorModel.findOne({accessToken: request.session.at});
}
github kriskowal / lode / node_modules / q / util.js View on Github external
exports.join = function (values, fulfilled) {
    var reasons;
    var fulfillment = Q.defer();
    var completion = values.reduce(function (done, value, i) {
        return Q.when(done, function () {
            return Q.when(value, function (value) {
                values[i] = value;
            }, function (reason) {
                reasons = reasons || [];
                reasons[i] = reason;
                fulfillment.reject(reason);
            });
        });
    }, undefined);
    Q.when(completion, fulfillment.resolve);
    return Q.when(fulfillment.promise, function () {
        return fulfilled ? fulfilled.apply(null, values) : values;
    }, function () {
        reasons = reasons || [];
        return Q.reject({
            "toString": function () {
                return "Can't join. " + reasons.join("; ");
            },
            "reasons": Q.when(completion, function () {
                return reasons;
            })
        });
    });
};