Nondeterministic Programming Methodology
Miss any of our Open RFC calls?Watch the recordings here! »

pateka

0.1.14 • Public • Published

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.

Install

npm i pateka

DownloadsWeekly Downloads

8

Version

0.1.14

License

MIT

Unpacked Size

27 kB

Total Files

13

Last publish

Collaborators

  • avatar