graph-simple-sequencer
Sort items in a graph using a topological sort into chunks
Last updated 8 years ago by thejameskyle .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install graph-simple-sequencer 
SYNC missed versions from official npm registry.

graph-simple-sequencer

Sort items in a graph using a topological sort into chunks

Install

yarn add graph-simple-sequencer

Usage

import graphSimpleSequencer from 'graph-simple-sequencer';

let graph = new Map([
  ["task-a", ["task-d"]], // task-a depends on task-d
  ["task-b", ["task-d", "task-a"]],
  ["task-c", ["task-d"]],
  ["task-d", ["task-a"]],
]);

let { safe, chunks } = graphSimpleSequencer(graph);
// { safe: false,
//   chunks: [['task-d'], ['task-a', 'task-b', 'task-c']] }

for (let chunk of chunks) {
  // Running tasks in parallel
  await Promise.all(chunk.map(task => exec(task)));
}

Cycles

Graph cycles are resolved by creating a new chunk with the item that has:

  1. The fewest number of remaining dependencies (to reduce risk of missing dependencies)
  2. The highest number of remaining dependents (to increase chance of unblocking dependents)

Current Tags

  • 1.0.3                                ...           latest (8 years ago)

4 Versions

  • 1.0.3                                ...           8 years ago
  • 1.0.2                                ...           8 years ago
  • 1.0.1                                ...           8 years ago
  • 1.0.0                                ...           8 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 3
Last Month 1
Dependencies (1)
Dev Dependencies (2)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |