How to use the q/util.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 / linkage.js View on Github external
.then(function (libTree) {
        // merge the mappings trees
        return Q.when(mappings, function (mappings) {
            var tree = {};
            Object.keys(mappings).forEach(function (key) {
                var mapping = mappings[key];
                var lib = mapping.lib;
                var ids = mapping.ids;
                ids.forEach(function (id) {
                    tree[fs.join(key, id)] = {
                        "reference": true,
                        "package": mapping.href,
                        "id": id
                    };
                });
            });
            update(tree, libTree);
            if (config.name && config.main) {
                tree[config.name] = {
github kriskowal / lode / lib / linkage.js View on Github external
function linkPackage(pkg, linkage, requires) {
    var config = pkg.config || {};
    var PkgModule = config.requireSecure ?
        require("./secure/init").Module :
        Module;
    var factories = {};

    Object.keys(pkg.lib).forEach(function (id) {
        var module = pkg.lib[id];
        factories[id] = linkModule(module, linkage, requires, PkgModule);
    });

    return Q.when(Q.shallow(factories), function (factories) {

        var require = Require({
            // TODO parameterize the scope
            "scope": {
                "console": console
            },
            "factories": factories,
            "supportDefine": config.supportDefine || config.requireDefine
        });

        return require;

    });
}
github kriskowal / lode / tests / fs.js View on Github external
exports['test ' + path] = function (ASSERT, done) {
        path = path.replace("{port}", port);
        var got = PACKAGE_FS.get(path, {"fs": FS, "http": HTTP});
        Q.when(got, function (got) {
            var fs = Root(got.fs, got.path);
            return Q.when(fs, function (fs) {
                var actuals = {
                    "list": fs.list(""),
                    "listTree": fs.listTree(""),
                    "read": fs.read("package.json", "r", "utf-8")
                };
                return eventuallyVerify(ASSERT, actuals, oracle);
            });
        }).then(done, function (reason) {
            ASSERT.ok(false, reason);
            done();
        });
    };
}
github kriskowal / lode / lodown.js View on Github external
function main() {
    var href = process.argv[2] || '';
    var engines = process.argv.slice(3);
    var got = PFS.get(href, {"fs": FS, "http": HTTP});
    return Q.when(got, function (got) {
        var options = {
            "engines": engines.length ? engines : ["lode", "node"],
            "debug": true,
            "fs": got.fs,
            "http": HTTP,
            "path": got.path,
            "href": got.href
        };
        return Q.when(LINK.loadLinkage(got.path, options), function (linkage) {
            return Q.when(LINK.read(linkage), function () {
                return Q.when(LINK.hash(linkage), function () {
                    console.log(JSON.stringify(linkage, function (key, value) {
                        if (["fs", "content", "javascript"].indexOf(key) >= 0)
                            return;
                        else
                            return value;
github kriskowal / lode / lib / linkage.js View on Github external
Object.keys(pkg.resources).forEach(function (path) {
                var resource = pkg.resources[path];
                var join = visitors.resource(resource, pkg, linkage, options);
                done = Q.when(done, function () {
                    return join;
                });
            });
        }
github kriskowal / lode / node_modules / q-fs / common.js View on Github external
function reroot(path) {
        path = path || exports.ROOT;
        return Q.when(exports.list(path), function (list) {
            if (list.length !== 1)
                return Root(exports, path);
            var nextPath = exports.join(path, list[0]);
            return Q.when(exports.stat(nextPath), function (stat) {
                if (stat.isDirectory()) {
                    return reroot(nextPath);
                } else {
                    return Root(exports, path);
                }
            });
        });
    }
github kriskowal / lode / lib / linkage.js View on Github external
return Q.when(info.includes || [], function (includes) {
        var done;
        includes.forEach(function (include) {
            done = Q.when(done, function () {
                loadDeepIncludes(include, lib, resources, included)
            });
        });
        done = Q.when(done, function () {
            return Q.when(info.lib, function (_lib) {
                update(lib, _lib);
                return Q.when(info.resources, function (_resources) {
                    update(resources, _resources);
                });
            });
        });
        return done;
    });
}
github kriskowal / lode / lib / linkage.js View on Github external
Object.keys(packages).forEach(function (href) {
        var pkg = packages[href];
        if (visitors.package) {
            var join = visitors.package(pkg, linkage, options);
            done = Q.when(done, function () {
                return join;
            });
        }
        if (visitors.module) {
            Object.keys(pkg.lib).forEach(function (id) {
                var module = pkg.lib[id];
                var join = visitors.module(module, pkg, linkage, options);
                done = Q.when(done, function () {
                    return join;
                });
            });
        }
        if (visitors.resource) {
            Object.keys(pkg.resources).forEach(function (path) {
                var resource = pkg.resources[path];
                var join = visitors.resource(resource, pkg, linkage, options);
github kriskowal / lode / lib / linkage.js View on Github external
return roots.map(function (root) {
                var list = root.fs.listTree("", function (path, stat) {
                    return stat.isFile();
                });
                return Q.when(list, function (list) {
                    var tree = {};
                    list.forEach(function (path) {
                        var extension = fs.extension(path);
                        var x = RegExp(regExpEscape(extension) + '$');
                        var id = path.replace(x, '');
                        var candidates = tree[id] = tree[id] || {};
                        candidates[extension] = {
                            "href": got.href.replace(/\/$/, "") + "/" + path,
                            "fs": root.fs,
                            "path": path,
                            "packagePath": got.fs.join(
                                got.fs.ROOT,
                                got.path,
                                root.path,
                                path
                            ),

q

A library for promises (CommonJS/Promises/A,B,D)

MIT
Latest version published 7 years ago

Package Health Score

63 / 100
Full package analysis