How to use vasync - 10 common examples

To help you get started, we’ve selected a few vasync 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 joyent / smartos-live / src / fw / lib / fw.js View on Github external
function saveRules(rules, log, callback) {
    var uuids = [];
    var versions = {};
    log.debug({ rules: rules }, 'saveRules: entry');

    return vasync.pipeline({
    funcs: [
        function _mkdir(_, cb) { mkdirp(RULE_PATH, cb); },
        function _writeRules(_, cb) {
            return vasync.forEachParallel({
                inputs: rules,
                func: function _writeRule(rule, cb2) {
                    var ser = rule.serialize();
                    // XXX: allow overriding version in the payload
                    var filename = util.format('%s/%s.json.%s', RULE_PATH,
                        rule.uuid, rule.version);
                    log.trace(ser, 'writing "%s"', filename);

                    return fs.writeFile(filename, JSON.stringify(ser, null, 2),
                        function (err) {
                        if (err) {
                            return cb2(err);
github joyent / smartos-live / src / fw / lib / rvm.js View on Github external
function save(vms, log, callback) {
    log.trace('rvm.save: entry');

    if (!vms || util_obj.objEmpty(vms)) {
        return callback();
    }

    var uuids = [];
    // XXX: allow overriding version in the payload
    var versions = {};
    var ver = mod_rule.generateVersion();

    return vasync.pipeline({
    funcs: [
        function _mkdir(_, cb) { mkdirp(VM_PATH, cb); },
        function _writeVMs(_, cb) {
            return vasync.forEachParallel({
                inputs: Object.keys(vms),
                func: function _writeVM(uuid, cb2) {
                    var vm = vms[uuid];
                    var filename = util.format('%s/%s.json.%s',
                        VM_PATH, uuid, ver);
                    log.trace(vm, 'writing "%s"', filename);

                    return fs.writeFile(filename, JSON.stringify(vm, null, 2),
                        function (err) {
                        if (err) {
                            return cb2(err);
                        }
github trentm / jirash / lib / cli / index.js View on Github external
JirashCli.prototype._emitCompletions = function _emitCompletions(type, cb) {
    assert.string(type, 'type');
    assert.func(cb, 'cb');

    // TODO: implement _emitCompletions

    var cacheFile = path.join(this.jirashapi.cacheDir, type + '.completions');
    var ttl = 5 * 60 * 1000; // timeout of cache file info (ms)

    vasync.pipeline(
        {
            arg: {},
            funcs: [
                function tryCacheFile(_, next) {
                    fs.stat(cacheFile, function onStat(err, stats) {
                        if (
                            !err &&
                            stats.mtime.getTime() + ttl >= new Date().getTime()
                        ) {
                            process.stdout.write(fs.readFileSync(cacheFile));
                            next(true); // early abort
                        } else if (err && err.code !== 'ENOENT') {
                            next(err);
                        } else {
                            next();
                        }
github joyent / node-workflow / lib / job-runner.js View on Github external
}

        var pipeline = chain_to_run.map(function (task) {
            return (function (_, cb) {
                if (task.modules && typeof (task.modules) === 'string') {
                    try {
                        task.modules = JSON.parse(task.modules);
                    } catch (e) {
                        delete task.modules;
                    }
                }
                return runTask(task, chain_results, cb);
            });
        });

        vasync.pipeline({
            funcs: pipeline
        }, function (err, results) {
            log.trace({results: results}, 'Pipeline results');
            // Whatever happened here, we are timeout done.
            if (timeoutId) {
                clearTimeout(timeoutId);
            }

            if (err) {
                // If we are cancelating job, we want to avoid running
                // "onerror" branch
                if (err === 'cancel') {
                    return onCancel(callback);
                } else {
                    return onError(err, callback);
                }
github joyent / sdc-docker / test / integration / helpers.js View on Github external
function _stepCreateClientZone(state_, cb) {
    assert.object(state_, 'state_');
    assert.func(cb, 'cb');

    if (state_.clientZone) {
        return cb();
    }

    var payload = state_.clientZonePayload;

    vasync.pipeline({arg: state_, funcs: [
        stepNapi,
        function payloadNetworks(state, next) {
            state.napi.listNetworks({name: 'external'}, function (err, nets) {
                if (err) {
                    return next(err);
                }
                payload.networks.push({uuid: nets[0].uuid});
                next();
            });
        },

        stepImgapi,
        function importImageIfNecessary(state, next) {
            state.imgapi.getImage(payload.image_uuid, function (err, img) {
                if (err && err.statusCode !== 404) {
                    return next(err);
github joyent / node-httpstream / tests / tst.httpstream.js View on Github external
function (_, callback) {
		var tests_to_run = process.argv.slice(2);
		if (tests_to_run.length === 0)
			tests_to_run = Object.keys(test_cases);
		var funcs = tests_to_run.map(function (k) {
			if (!test_cases.hasOwnProperty(k))
				throw (new VError(
				    'unknown test name: "%s"', k));
			return (runTestCase.bind(null, k, test_cases[k]));
		});
		mod_vasync.pipeline({ 'funcs': funcs }, callback);
	},
github joyent / manatee / test / testManatee.js View on Github external
Manatee.prototype.start = function start(cb) {
    var self = this;
    var log = self.log;
    var spawnSitterOpts = ['-l', 'child', '-o', 'noorphan', 'node',
        '--abort-on-uncaught-exception', '../sitter.js', '-vvv', '-f',
        self.sitterCfgLocation || './etc/sitter.json'];
    var spawnBsOpts = ['-l', 'child', '-o', 'noorphan', 'node',
        '--abort-on-uncaught-exception', '../backupserver.js', '-vvv', '-f',
        self.bsCfgLocation || './etc/backupserver.json'];
    var spawnSsOpts = ['-l', 'child', '-o', 'noorphan', 'node',
        '--abort-on-uncaught-exception', '../snapshotter.js', '-vvv', '-f',
        self.ssCfgLocation || './etc/snapshotter.json'];

    vasync.pipeline({funcs: [
        function _createLogFiles(_, _cb) {
            self.sitterLog = fs.createWriteStream(self.sitterLogPath);
            self.sitterLog.on('error', function (err) {
                log.error({err: err}, 'sitter logging stream got error');
            });
            self.ssLog = fs.createWriteStream(self.ssLogPath);
            self.ssLog.on('error', function (err) {
                log.error({err: err}, 'snapshotter logging stream got error');
            });
            self.bsLog = fs.createWriteStream(self.bsLogPath);
            self.bsLog.on('error', function (err) {
                log.error({err: err}, 'backupserver logging stream got error');
            });
            return _cb();
        },
        function _startSitter(_, _cb) {
github trentm / jirash / lib / jirashapi.js View on Github external
JirashApi.prototype.deleteVersion = function deleteVersion(opts, cb) {
    assert.ok(/^\d+$/.test(opts.id.toString()), 'opts.id (number)');
    assert.func(cb, 'cb');

    var context = {
        api: this
    };

    vasync.pipeline(
        {
            arg: context,
            funcs: [
                ctxJiraClient,

                function doIt(ctx, next) {
                    ctx.jiraClient.del(
                        {
                            path: format('/rest/api/2/version/%s', opts.id)
                        },
                        function onRes(err, req, res, _body) {
                            next(err);
                        }
                    );
                }
            ]
github trentm / jirash / lib / cli / do_version / do_get.js View on Github external
}

    var context = {
        cli: this.top
    };
    if (args.length === 1) {
        context.verId = args[0];
    } else if (args.length === 2) {
        context.verProject = args[0];
        context.verName = args[1];
    } else {
        cb(new UsageError('incorrect number of args'));
        return;
    }

    vasync.pipeline(
        {
            arg: context,
            funcs: [
                versioncommon.ctxVer,

                function printVer(ctx, next) {
                    console.log(JSON.stringify(ctx.ver, null, 4));
                    next();
                }
            ]
        },
        cb
    );
}
github restify / node-restify / benchmark / lib / bench.js View on Github external
function runBenchmark(opts, handler, version, cb) {
    if (opts.track) {
        console.log(version.toUpperCase() + ':');
    }

    var spinner = ora('Started ' + version + '/' + handler).start();
    var modulePath = path.join(__dirname, '../benchmarks', handler);
    var url = require(modulePath).url;
    var forked = fork(modulePath, ['version=' + version]);

    pipeline(
        {
            funcs: [
                function warm(_, callback) {
                    spinner.color = 'magenta';
                    spinner.text =
                        'Warming ' + version + '/' + handler + ' for 5s';

                    var fireOpts = Object.assign({}, opts, {
                        duration: 5,
                        url: url
                    });
                    autocannon.fire(
                        fireOpts,
                        handler,
                        version,
                        false,

vasync

utilities for observable asynchronous control flow

MIT
Latest version published 3 years ago

Package Health Score

59 / 100
Full package analysis

Popular vasync functions