• Stars
    star
    170
  • Rank 223,357 (Top 5 %)
  • Language
    JavaScript
  • Created almost 11 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Execute tasks asynchronous tasks on web Worker without seperate files.

AsyncTask Travis Code Climate

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((a, b) => a + b)

task.execute(1, 2)
  .then(function( result ) {
    result === 3
  })
  .catch( handleException )

API

AsyncTask( doInBackground, options )

Creates a new AsyncTask

options
  • 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(() => 'a', {worker})

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


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

More Repositories

1

batshit

A batch manager that will deduplicate and batch requests for a certain data type made within a window. Useful to batch requests made from multiple react components that uses react-query
TypeScript
108
star
2

node-pad

Game controllers for node, only Dualshock3 support atm
JavaScript
21
star
3

service-outbox

Transactional outbox pattern for node and mongodb
TypeScript
17
star
4

background-worker

JavaScript
8
star
5

lavaK

Javascript hotkeys.
JavaScript
5
star
6

use-saga-reducer

Use redux-saga with react reducer hook, with convenience methods for running sagas from components.
TypeScript
4
star
7

func-match

Pattern matching
JavaScript
4
star
8

vayup

Vayup | Yogic Breathing. Calm and vitalize using breath
TypeScript
3
star
9

fp-ts-http

Opinionated, strongly typed http middleware library using fp-ts fp-ts-routing and io-ts for decoding of io
TypeScript
3
star
10

Scope.js

Useless library for creating new scopes and preventing global leakage
JavaScript
2
star
11

build-the-future-with-zeitgeist-workshop

A tick tack toe game using event sourcing and prediction markets. This is the code for the talk given at the Polkadot Global Series North America edition for Zeitgeist.pm.
TypeScript
1
star
12

nodeapps.wtw.no

JavaScript
1
star
13

playlistsforsoundcloud_server

Server for the playlistsforsoundcloud chrome app
JavaScript
1
star
14

flo

Control flow library for nodejs and the browser
JavaScript
1
star
15

makalu

Basecamp command line tools
JavaScript
1
star
16

gorillatron.me

gorillatron.me
JavaScript
1
star
17

changesorg.com

PHP
1
star
18

manaslu

Nodejs basecamp API/SDK
JavaScript
1
star
19

graphql-html-sanitizer

Graphql html sanitizing directive and scalar type
TypeScript
1
star
20

purescript-bf-gun

Gun DB bindings in purescript.
PureScript
1
star
21

node_jobs

JavaScript
1
star
22

Solitude

A clutter less writing tool for writers who want some inspiration ala tweets while they write
JavaScript
1
star
23

FabulousGorilla

My sublime text 2 things. Only theme atm
1
star
24

purs-vite-template

JavaScript
1
star