JavaScript library that streamlines real asynchronous code execution through use of web workers.
async(action [, scope] [, args])-
action- Function to be executed asynchronously. It's important to note that the it needs to be serializable, so it all external references must be injected through eitherscopeorargsparameters. -
scope- Scope ofthiswithin the action body. It must be JSON serializable. -
args- ArgumentsArrayto be passed to theactioncall. All arguments must also be JSON serializable. -
returns
Promiseinstance - Resolves with return value ofaction. Rejects with uncaughtErrorinstance.Promise.cancel()aborts associated async execution.
The Worker pool size can be configured with the pool method.
async.pool(size)size- Worker pool size. Default:8
async(function () {
return 'Hello World!'
})
.then(function (data) {
console.log(data)
})Prints Hello World
async(function (x, y) {
return this.total + x * y
}, {total: 1}, [2, 3])
.then(function (result) {
console.log(result)
})Prints 7