asynckit
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Asynckit is a minimal yet highly efficient asynchronous jobs utility library designed with streams support. It provides a harness for both parallel
and serial
iterators over lists of items, depicted as arrays or objects. Furthermore, the library also accommodates an abort function and can terminate leftover jobs upon detecting an error. This is particularly beneficial for maintaining stability during operations and preventing errors due to exceeding the maximum call stack size, potentially caused by synchronous iterators.
Asynckit can be installed by using npm install:
$ npm install --save asynckit
To use the Asynckit utility library, you can follow these examples.
var parallel = require('asynckit').parallel,
assert = require('assert');
var source = [ 1, 1, 4, 16, 64, 32, 8, 2 ],
expectedResult = [ 2, 2, 8, 32, 128, 64, 16, 4 ],
expectedTarget = [ 1, 1, 2, 4, 8, 16, 32, 64 ],
target = [];
parallel(source, asyncJob, function(err, result)
{
assert.deepEqual(result, expectedResult);
assert.deepEqual(target, expectedTarget);
});
function asyncJob(item, cb)
{
var delay = item * 25;
var timeoutId = setTimeout(function() {
target.push(item);
cb(null, item * 2);
}, delay);
return clearTimeout.bind(null, timeoutId);
}
var serial = require('asynckit').serial
assert = require('assert');
var source = { first: 1, one: 1, four: 4, sixteen: 16, sixtyFour: 64, thirtyTwo: 32, eight: 8, two: 2 },
expectedResult = { first: 2, one: 2, four: 8, sixteen: 32, sixtyFour: 128, thirtyTwo: 64, eight: 16, two: 4 },
expectedTarget = [ 1, 1, 4, 16, 64, 32, 8, 2 ],
target = [];
serial(source, asyncJob, function(err, result)
{
assert.deepEqual(result, expectedResult);
assert.deepEqual(target, expectedTarget);
});
function asyncJob(item, cb)
{
target.push(item);
cb(null, item * 2);
}
These examples demonstrate basic usage. More comprehensive examples can be found in the test folder of the Asynckit library repo.
The Asynckit documentation can be found directly in the GitHub repo accessible via https://github.com/alexindigo/asynckit.git. All the examples and functional details are included in the README file there. Further examples are available in the provided "test" folders found in the repository. You can also find more information or ask a question in the "issues" section of the GitHub repository.