Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ecollect/pateka
Ordered pararallel asynchronous tasks.
https://github.com/ecollect/pateka
async await nodejs parallel promise queue tasks worker
Last synced: 7 days ago
JSON representation
Ordered pararallel asynchronous tasks.
- Host: GitHub
- URL: https://github.com/ecollect/pateka
- Owner: eCollect
- License: mit
- Created: 2018-10-16T07:46:34.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T03:54:36.000Z (almost 2 years ago)
- Last Synced: 2023-12-23T12:04:41.607Z (11 months ago)
- Topics: async, await, nodejs, parallel, promise, queue, tasks, worker
- Language: JavaScript
- Size: 354 KB
- Stars: 0
- Watchers: 5
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
pateka - ordered parallel asynchronous tasks
## Installation
```shell
$ 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.
```javascript
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.
```javascript
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.
```javascript
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
```javascript
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) license.