pateka
Ordered parallel asynchronous tasks.
Last updated 7 months ago by nanov .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install pateka 
SYNC missed versions from official npm registry.

pateka - ordered parallel asynchronous tasks

travis npm version Coverage Status Known Vulnerabilities MIT Licence

Installation

$ npm install pateka

Usage

Creating a new pateka. By default a pateka will be created with (parallel) 256 tracks, each track than will be filled with async tasks based on their routing key. Tasks in the same track ( same routing key ) will be run in order, tracks will be run in parallel.

const Pateka = require('pateka');

const Pateka = new Pateka();

Setting the number of (parallel) tracks

You can chnage the default number of tracks by passing a tracks option to the constructor.

const Pateka = new Pateka({  tracks: 128 });

Adding tasks

Task are added with the add method. You will need to specify an id for the task, a task function, and a routingKey.

The routingKey will be used to spread tasks into tracks, ensuring that tasks with the same key are always run in the right order and sequence.

pateka.add({
	routingKey: 'order-1234', // shared between tasks that needs tp be run in sequence
	id: '713973e256ab63505cba325344d30dbb', // unique for this task
	async task () {
		// do some work on this order
	}
});

pateka.add({
  routingKey: 'order-1234', // shared between tasks that needs tp be run in sequence
  id: ' 2cd96bc0d5b0d2e6520ef04fa9f887b9', // unique for this task
  async task () {
		// do some additional work on this order, after the other work has fhinished
	}
});

Awaiting a task to be done

await pateka.add({
  routingKey: 'order-1234', // shared between tasks that needs tp be run in sequence
  id: ' 2cd96bc0d5b0d2e6520ef04fa9f887b9', // unique for this task
  async task () {
		// do some additional work on this order, after the other work has fhinished
	}
});

License

Copyright (c) 2018 eCollect AG. Licensed under the MIT license.

Current Tags

  • 0.1.14                                ...           latest (7 months ago)

6 Versions

  • 0.1.14                                ...           7 months ago
  • 0.1.13                                ...           7 months ago
  • 0.1.12                                ...           a year ago
  • 0.1.11                                ...           2 years ago
  • 0.1.1                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (8)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |