https://github.com/nyurik/parallel-actions
This library simplifies running actions with dependencies in parallel, ensuring their dependencies finish first.
https://github.com/nyurik/parallel-actions
Last synced: about 1 month ago
JSON representation
This library simplifies running actions with dependencies in parallel, ensuring their dependencies finish first.
- Host: GitHub
- URL: https://github.com/nyurik/parallel-actions
- Owner: nyurik
- License: mit
- Created: 2019-10-24T01:48:38.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T05:00:53.000Z (about 2 years ago)
- Last Synced: 2025-03-07T16:09:55.447Z (about 2 months ago)
- Language: JavaScript
- Size: 114 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# parallel-actions
This library simplifies running parallel actions with dependencies, ensuring only the actions with complete dependencies run in parallel.
## Example
Run multiple SQL commands that require certain ordering, e.g. `REFRESH MATERIALIZED VIEW` must be run in the order of their dependencies.
In this example we refresh 3 materialized views, two of which are based on real tables, and the 3rd depends on the first two.
`parallel-actions` lib will simplify execution, making sure `v3` does not start until `v1` and `v2` are complete.```js
const { Pool } = require('pg');
const pexec = require('parallel-actions');async function run() {
// Use PostgreSQL pool to run queries and restrict
// the number of simultaneous connections.
const pgpool = new Pool({
max: 5,
host: '...', port: '...', database: '...',
});// Which views we need to refresh
const views = {
v1: {view: 'view1'},
v2: {view: 'view2'},
v3: {view: 'view3', dependsOn: ['v1', 'v2']},
};
await pexec(views,
v => pgpool.query(`REFRESH MATERIALIZED VIEW ${v.view};`)
);
}
```