Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (error) throw error;
console.log('Goodbye!');
});
// Task with Reuslts -------------------------------------------------
// await
qWithResults
.await(function (error, file1Stat, file2Stat) {
if (error) throw error;
console.log(file1Stat, file2Stat);
});
// awaitAll
qWithResults = d3Queue.queue()
.defer(getFileStats, './workingpath/file1.json')
.defer(getFileStats, './yetanotherworkingpath/file2.json')
.awaitAll(function (error, fileStats) {
if (error) throw error;
console.log(fileStats[0], fileStats[1]);
});
// Abort Deferred Tasks ==============================================
function requestDataFromInterWeb(url: string, callback: (error: any | null, data?: any) => void) {
// magically get data from the interweb, e.g. like d3-request would, while supporting an abort() method
}
qWithResults = d3Queue.queue()
.defer(requestDataFromInterWeb, 'http://www.google.com:81')
if (error) throw error;
console.log('Goodbye!');
});
// Task with Reuslts -------------------------------------------------
// await
qWithResults
.await((error, file1Stat, file2Stat) => {
if (error) throw error;
console.log(file1Stat, file2Stat);
});
// awaitAll
qWithResults = d3Queue.queue()
.defer(getFileStats, './workingpath/file1.json')
.defer(getFileStats, './yetanotherworkingpath/file2.json')
.awaitAll((error, fileStats) => {
if (error) throw error;
console.log(fileStats[0], fileStats[1]);
});
// Abort Deferred Tasks ==============================================
function requestDataFromInterWeb(url: string, callback: (error: any | null, data?: any) => void) {
// magically get data from the interweb, e.g. like d3-request would, while supporting an abort() method
}
qWithResults = d3Queue.queue()
.defer(requestDataFromInterWeb, 'http://www.google.com:81')
.defer(requestDataFromInterWeb, 'http://www.google.com:81')
* are not intended as functional tests.
*/
import * as d3Queue from 'd3-queue';
// -------------------------------------------------------------------
// Test Queue
// -------------------------------------------------------------------
// Create queue ======================================================
let qNoResult: d3Queue.Queue;
let qWithResults: d3Queue.Queue;
// With default concurrency
qNoResult = d3Queue.queue();
// With limited concurrency
qWithResults = d3Queue.queue(3);
// Defer Tasks =======================================================
// No Results Task ---------------------------------------------------
function delayedHello(name: string, delay: number, callback: (error: any | null) => void) {
setTimeout(function () {
console.log('Hello, ' + name + '!');
callback(null);
}, delay);
}
* are not intended as functional tests.
*/
import * as d3Queue from 'd3-queue';
// -------------------------------------------------------------------
// Test Queue
// -------------------------------------------------------------------
// Create queue ======================================================
let qNoResult: d3Queue.Queue;
let qWithResults: d3Queue.Queue;
// With default concurrency
qNoResult = d3Queue.queue();
// With limited concurrency
qWithResults = d3Queue.queue(3);
// Defer Tasks =======================================================
// No Results Task ---------------------------------------------------
function delayedHello(name: string, delay: number, callback: (error: any | null) => void) {
setTimeout(() => {
console.log('Hello, ' + name + '!');
callback(null);
}, delay);
}
qNoResult = qNoResult.defer(delayedHello, 'Alice', 250);
readers.readDbf = function (filePath, opts_, cb) {
var parserOptions = {
map: function (d) { return d }
}
if (typeof cb === 'undefined') {
cb = opts_
} else {
parserOptions = _.isFunction(opts_) ? {map: opts_} : opts_
}
var reader = shapefileDbf.reader(filePath)
var rows = []
var headers
// Run these in order
queue(1)
.defer(readHeader)
.defer(readAllRecords)
.defer(close)
.await(function (error, readHeaderData, readAllRecordsData, jsonData) {
// We're using queue to work through this flow
// As a result, `readHeaderData`, `readAllRecordsData` are going to be undefined
// Because they aren't meant to return anything, just process data
// `rowData`, however contains all our concatenated data, so let's return that
cb(error, jsonData)
})
function readHeader (callback) {
reader.readHeader(function (error, header) {
if (error) {
return callback(error)
}
];
var addLuaFiles = (directory, callback) => {
fs.readdir(path.normalize(directory), (err, files) => {
if (err) return callback(err);
var luaFiles = files.filter(f => !!f.match(/\.lua$/)).map(f => path.normalize(directory + '/' + f));
Array.prototype.push.apply(dependencies, luaFiles);
callback();
});
};
// Note: we need a serialized queue here to ensure that the order of the files
// passed is stable. Otherwise the hash will not be stable
d3.queue(1)
.defer(addLuaFiles, this.PROFILES_PATH)
.defer(addLuaFiles, this.PROFILES_PATH + '/lib')
.awaitAll(hash.hashOfFiles.bind(hash, dependencies, callback));
};
// use the mode of the first step of the route
// for routability table test, we can assume the mode is the same throughout the route,
// since the route is just a single way
if( r.json.routes[0].legs[0] && r.json.routes[0].legs[0].steps[0] ) {
r.mode = r.json.routes[0].legs[0].steps[0].mode;
}
} else {
r.status = null;
}
}
callback(null, r);
});
};
d3.queue(1)
.defer(testDirection, 'forw')
.defer(testDirection, 'backw')
.awaitAll((err, res) => {
if (err) return cb(err);
// check if forw and backw returned the same values
res.forEach((dirRes) => {
var which = dirRes.which;
delete dirRes.which;
result[which] = dirRes;
});
result.bothw = {};
var sq = d3.queue();
var parseRes = (key, scb) => {
this.extractContractPartitionAndCustomize = (callback) => {
// a shallow copy of scenario parameters to avoid data inconsistency
// if a cucumber timeout occurs during deferred jobs
let p = {extractArgs: this.extractArgs, contractArgs: this.contractArgs,
partitionArgs: this.partitionArgs, customizeArgs: this.customizeArgs,
profileFile: this.profileFile, inputCacheFile: this.inputCacheFile,
processedCacheFile: this.processedCacheFile, environment: this.environment};
let queue = d3.queue(1);
queue.defer(this.extractData.bind(this), p);
queue.defer(this.partitionData.bind(this), p);
queue.defer(this.contractData.bind(this), p);
queue.defer(this.customizeData.bind(this), p);
queue.awaitAll(callback);
};
module.exports.init = function (t) {
const q = queue(1);
q.defer(dynalite.listen.bind(dynalite), 4568);
q.defer(kinesalite.listen.bind(kinesalite), 5568);
q.defer(kinesisClient.createStream.bind(kinesisClient), {
ShardCount: process.env.shardCount || 2,
StreamName: config.streamName
});
q.await((err) => {
if (err && err.code != 'ResourceInUseException') t.fail(err.stack);
console.log(`Dynalite started on port 4568, Kinesalite started on port 5568, created stream ${config.streamName}`);
t.end();
});
};