Methods
(static) each(items, task, 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 |
|
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, errpos) => {
//> err = [ , 'error', ]
//> res = [1, 4, 5]
//> errpos = [1]
}
)
(static) eachLimit(limit, items, task, 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 |
|
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, errpos) => {
//> err = [ , 'error', , 'error']
//> res = [1, 4, 5, 7]
//> errpos = [1, 3]
}
)
(static) parallel(tasks, 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 |
|
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, errpos) => {
//> err = [ ,'error', ]
//> res = [1, 2, 3]
//> errpos = [1]
})
(static) parallelLimit(limit, tasks, 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 |
|
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, errorpos) => {
//> err = [ ,'error', ]
//> res = [1, 2, 3]
//> errorpos = [1]
})
(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