Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

async-task

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-task

Run a AsyncTask using a web worker or child_process.

  • 0.4.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
44
decreased by-41.33%
Maintainers
1
Weekly downloads
 
Created
Source

AsyncTask Travis

Execute tasks asynchronous tasks without seperate files. In browsers without Worker support it fallbacks to iframe.

In Nodejs it spawns a process using child_process.

Install

npm install async-task

Also support bower

bower install async-task

Usage

var AsyncTask = require( 'async-task' )

var task = new AsyncTask({
  doInBackground: (a, b) -> a + b
})

task.execute(1, 2)
  .then(function( result ) {
    result === 3
  })
  .catch( handleException )
Shorthand
var task = new AsyncTask( (a, b) -> a + b, options )

API

AsyncTask( doInBackground, options )

Creates a new AsyncTask

options
  • options.doInBackground The work(function) to be done in the worker if the first argument isnt the task.
  • options.keepAlive Keep worker alive so .execute can be called multiple times.
  • options.worker Supply worker if you want to share worker between tasks. NB!: termination of worker is left to the user
asyncTask.execute( args... ):Promise

Execute the doInBackground function with supplied args.

Sharing worker example
var AsyncTask = require( 'async-task' )
var BackgroundWorker = require( 'background-worker' )

var worker = new BackgroundWorker({})

var taskA = new AsyncTask({
  worker: worker,
  doInBackground: () -> 'a'
})

var taskB = new AsyncTask({
  worker: worker,
  doInBackground: () -> 'b'
})


Promise.all([
  taskA.execute(),
  taskB.execute()
]).then(function(result) {
  result == [ 'a', 'b' ]
  worker.terminate()
})
Test

npm run-script test

Roadmap

  • doInBackground can return a promise or maybe even a generator* so you can iterate over asyncTask.execute

In the wild

If your using it in your very cool project please drop me a note on jornandretangen àt gmail.com

Partially made, with <3 at:

Foo

FAQs

Package last updated on 26 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc