Methods
(static) each(items, task, optionsopt, callbackopt)
Run items
on async task
function in parallel.
Does not stop parallel execution on errors. All tasks get executed.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
items |
Array | Array of items |
|||||||||||||
task |
function | iterator function of type |
|||||||||||||
options |
Object |
<optional> |
Properties
|
||||||||||||
callback |
function |
<optional> |
optional callback function called by last
terminating function from |
Example
each([1, 2, 3],
(item, cb, index) => {
cb(index % 2 ? null : 'error', item + index)
}, (err, res) => {
//> err.errors = [null, 'error', null]
//> err.errpos = [1]
//> res = [1, 4, 5]
}
)
(static) eachLimit(limit, items, task, optionsopt, callbackopt)
Run items
on async task
function in parallel limited to limit
parallel.
Does not stop parallel execution on errors. All tasks get executed.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
limit |
Number | number of tasks running in parallel |
|||||||||||||
items |
Array | Array of items |
|||||||||||||
task |
function | iterator function of type |
|||||||||||||
options |
Object |
<optional> |
Properties
|
||||||||||||
callback |
function |
<optional> |
optional callback function called by last
terminating function from |
- Source:
Example
eachLimit(2, [1, 2, 3, 4],
(item, cb, index) => {
cb(index % 2 ? null : 'error', item + index)
}, (err, res) => {
//> err.errors = [null, 'error', null, 'error']
//> err.errpos = [1, 3]
//> res = [1, 4, 5, 7]
}
)
(static) parallel(tasks, optionsopt, callbackopt)
Run tasks
callback functions in parallel.
Does not stop parallel execution on errors. All tasks get executed.
The optional callback
gets called after the longest running task finishes.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tasks |
Array.<function()> | Array of callback functions of type |
|||||||||||||
options |
Object |
<optional> |
Properties
|
||||||||||||
callback |
function |
<optional> |
optional callback function called by last
terminating function from |
- Source:
Example
parallel([
(cb) => { cb(null, 1) },
(cb) => { cb('error', 2) },
(cb) => { cb(null, 3) }
], (err, res) => {
//> err.errors = [null, 'error', null]
//> err.errpos = [1]
//> res = [1, 2, 3]
})
(static) parallelLimit(limit, tasks, optionsopt, callbackopt)
Run tasks
callback functions in parallel limited to limit
parallel
running tasks.
Does not stop parallel execution on errors. All tasks get executed.
The optional callback
gets called after the longest running task finishes.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
limit |
Number | number of tasks running in parallel |
|||||||||||||
tasks |
Array | Array of callback functions of type |
|||||||||||||
options |
Object |
<optional> |
Properties
|
||||||||||||
callback |
function |
<optional> |
optional callback function called by last
terminating function from |
- Source:
Example
// runs 2 tasks in parallel
parallelLimit(2, [
(cb) => { cb(null, 1) },
(cb) => { cb('error', 2) },
(cb) => { cb(null, 3) }
], (err, res) => {
//> err.errors = [null, 'error', null]
//> err.errorpos = [1]
//> res = [1, 2, 3]
})
(static) queue(task, concurrency) → {Queue}
Run queued items
through an asynchronous task
.
Once finishing the task
an optional callback is called.
While pushing to the queue, you may define a priority for execution.
Lower values means faster execution.
See full API here Queue
.
Parameters:
Name | Type | Description |
---|---|---|
task |
function | iterator function of type |
concurrency |
Number | max. number of tasks running in parallel |
Returns:
- Type
- Queue