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 eitherscope
orargs
parameters. -
scope
- Scope ofthis
within the action body. It must be JSON serializable. -
args
- ArgumentsArray
to be passed to theaction
call. All arguments must also be JSON serializable. -
returns
Promise
instance - Resolves with return value ofaction
. Rejects with uncaughtError
instance.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