0.2.2 • Published 3 years ago

topological-promise-queue v0.2.2

Weekly downloads
5
License
MIT
Repository
github
Last release
3 years ago

topological-promise-queue

Run promises in order of a directed acyclic graph

In a dependency graph like below, we need to run dependencies first:

     A
   /   \
  B     C
  |
  C

That means, order of execution would be first C, then B, then A.


The queue could run tasks in parallel, this means we will try to reduce the time of execution as much as possible.

Given the following graph:

     A
   / | \
  B  C  D

This means, order of execution would be B, C and D in parallel, then A.

The amount of concurrency could be defined for limiting resource usage.


Usage

import { run } from "topological-promise-queue";

await run({
  concurrency: 10,
  edges: [
    // a depends on b
    ["a", "b"],
    // a depends on c
    ["a", "c"],
    // b depends on c
    ["b", "c"],
  ],
  async runner(node) {
    console.log(node);
    // this will output:
    // c
    // b
    // a
  },
});
0.2.1

3 years ago

0.2.0

3 years ago

0.2.2

3 years ago

0.1.0

3 years ago