Skip to content

JavaScript library that streamlines real asynchronous code execution through use of web workers

Notifications You must be signed in to change notification settings

ulisses-alves/async

Repository files navigation

Async

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 either scope or args parameters.

  • scope - Scope of this within the action body. It must be JSON serializable.

  • args - Arguments Array to be passed to the action call. All arguments must also be JSON serializable.

  • returns Promise instance - Resolves with return value of action. Rejects with uncaught Error instance. Promise.cancel() aborts associated async execution.

Worker Pool

The Worker pool size can be configured with the pool method.

async.pool(size)
  • size - Worker pool size. Default: 8

Usage

Simple

async(function () {
  return 'Hello World!'
})
.then(function (data) {
  console.log(data)
})

Prints Hello World

With scope & args

async(function (x, y) {
  return this.total + x * y
}, {total: 1}, [2, 3])
.then(function (result) {
  console.log(result)
})

Prints 7

About

JavaScript library that streamlines real asynchronous code execution through use of web workers

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published