Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'vasync' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
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);
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);
}
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();
}
}
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);
}
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);
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);
},
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) {
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);
}
);
}
]
}
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
);
}
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,