{"_id":"task-graph-runner","_rev":"269689","name":"task-graph-runner","description":"Run async tasks with dependencies","dist-tags":{"latest":"1.0.3"},"maintainers":[{"name":"thejameskyle","email":"me@thejameskyle.com"}],"time":{"modified":"2021-06-03T17:18:05.000Z","created":"2017-12-27T03:33:38.441Z","1.0.3":"2019-12-16T18:35:43.437Z","1.0.2":"2018-03-08T20:32:25.077Z","1.0.1":"2017-12-27T06:04:56.433Z","1.0.0":"2017-12-27T03:33:38.441Z"},"users":{},"author":{"name":"James Kyle","email":"me@thejameskyle.com"},"repository":{"type":"git","url":"git+https://github.com/thejameskyle/task-graph-runner.git"},"versions":{"1.0.3":{"name":"task-graph-runner","version":"1.0.3","description":"Run async tasks with dependencies","main":"index.js","repository":{"type":"git","url":"git+https://github.com/thejameskyle/task-graph-runner.git"},"author":{"name":"James Kyle","email":"me@thejameskyle.com"},"license":"MIT","keywords":["graph","adjacency","list","tasks","priority","priorities","sort","dependencies","topological","topo","sequencer","task","runner"],"scripts":{"flow":"flow status","test":"ava test.js"},"devDependencies":{"ava":"^0.24.0","flow-bin":"^0.61.0"},"dependencies":{"array-includes":"^3.0.3"},"gitHead":"15ea33b80454c4a4f537fbd4e80288032c4e2404","bugs":{"url":"https://github.com/thejameskyle/task-graph-runner/issues"},"homepage":"https://github.com/thejameskyle/task-graph-runner#readme","_id":"task-graph-runner@1.0.3","_nodeVersion":"12.9.1","_npmVersion":"6.11.3","dist":{"shasum":"73b2cd380cef6f51b8179b0d1da4bb7c356b03bf","size":2896,"noattachment":false,"key":"/task-graph-runner/-/task-graph-runner-1.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/task-graph-runner/download/task-graph-runner-1.0.3.tgz"},"maintainers":[{"name":"thejameskyle","email":"me@thejameskyle.com"}],"_npmUser":{"name":"thejameskyle","email":"me@thejameskyle.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/task-graph-runner_1.0.3_1576521343279_0.7137633012291758"},"_hasShrinkwrap":false,"publish_time":1576521343437,"_cnpm_publish_time":1576521343437},"1.0.2":{"name":"task-graph-runner","version":"1.0.2","description":"Run async tasks with dependencies","main":"index.js","repository":{"type":"git","url":"git+https://github.com/thejameskyle/task-graph-runner.git"},"author":{"name":"James Kyle","email":"me@thejameskyle.com"},"license":"MIT","keywords":["graph","adjacency","list","tasks","priority","priorities","sort","dependencies","topological","topo","sequencer","task","runner"],"files":["index.js"],"scripts":{"flow":"flow status","test":"ava test.js"},"devDependencies":{"ava":"^0.24.0","flow-bin":"^0.61.0"},"dependencies":{"array-includes":"^3.0.3"},"gitHead":"bf6914769aec5f7aef2582cc10c91f5cadcfe518","bugs":{"url":"https://github.com/thejameskyle/task-graph-runner/issues"},"homepage":"https://github.com/thejameskyle/task-graph-runner#readme","_id":"task-graph-runner@1.0.2","_npmVersion":"5.6.0","_nodeVersion":"8.9.4","_npmUser":{"name":"thejameskyle","email":"me@thejameskyle.com"},"dist":{"shasum":"dfc73e4f92d74b974a854ccd3b2a8c7f1fbf4137","size":2900,"noattachment":false,"key":"/task-graph-runner/-/task-graph-runner-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/task-graph-runner/download/task-graph-runner-1.0.2.tgz"},"maintainers":[{"name":"thejameskyle","email":"me@thejameskyle.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/task-graph-runner_1.0.2_1520541145017_0.5743746362857638"},"_hasShrinkwrap":false,"publish_time":1520541145077,"_cnpm_publish_time":1520541145077},"1.0.1":{"name":"task-graph-runner","version":"1.0.1","description":"Run async tasks with dependencies","main":"index.js","repository":{"type":"git","url":"git+https://github.com/thejameskyle/task-graph-runner.git"},"author":{"name":"James Kyle","email":"me@thejameskyle.com"},"license":"MIT","keywords":["graph","adjacency","list","tasks","priority","priorities","sort","dependencies","topological","topo","sequencer","task","runner"],"files":["index.js"],"scripts":{"flow":"flow status","test":"ava test.js"},"devDependencies":{"ava":"^0.24.0","flow-bin":"^0.61.0"},"dependencies":{"array-includes":"^3.0.3"},"gitHead":"303f20d88c459932e560964671efc8e12ce3c2ee","bugs":{"url":"https://github.com/thejameskyle/task-graph-runner/issues"},"homepage":"https://github.com/thejameskyle/task-graph-runner#readme","_id":"task-graph-runner@1.0.1","_npmVersion":"5.5.1","_nodeVersion":"8.9.1","_npmUser":{"name":"thejameskyle","email":"me@thejameskyle.com"},"dist":{"shasum":"321eb31f06b915dd9504e369187d11c14ddc6b26","size":2893,"noattachment":false,"key":"/task-graph-runner/-/task-graph-runner-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/task-graph-runner/download/task-graph-runner-1.0.1.tgz"},"maintainers":[{"name":"thejameskyle","email":"me@thejameskyle.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/task-graph-runner-1.0.1.tgz_1514354696360_0.35349812265485525"},"directories":{},"publish_time":1514354696433,"_hasShrinkwrap":false,"_cnpm_publish_time":1514354696433},"1.0.0":{"name":"task-graph-runner","version":"1.0.0","description":"Run async tasks with dependencies","main":"index.js","repository":{"type":"git","url":"git+https://github.com/thejameskyle/task-graph-runner.git"},"author":{"name":"James Kyle","email":"me@thejameskyle.com"},"license":"MIT","keywords":["graph","adjacency","list","tasks","priority","priorities","sort","dependencies","topological","topo","sequencer","task","runner"],"files":["index.js"],"scripts":{"flow":"flow status","test":"ava test.js"},"devDependencies":{"ava":"^0.24.0","flow-bin":"^0.61.0"},"dependencies":{"array-includes":"^3.0.3"},"gitHead":"5fa09f1b13ccbaf87afd8a1f65c1bf084de4e20a","bugs":{"url":"https://github.com/thejameskyle/task-graph-runner/issues"},"homepage":"https://github.com/thejameskyle/task-graph-runner#readme","_id":"task-graph-runner@1.0.0","_npmVersion":"5.5.1","_nodeVersion":"8.9.1","_npmUser":{"name":"thejameskyle","email":"me@thejameskyle.com"},"dist":{"shasum":"d80ccd2df5321154206e51ca3a2edb4e8d7ae6d6","size":2876,"noattachment":false,"key":"/task-graph-runner/-/task-graph-runner-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/task-graph-runner/download/task-graph-runner-1.0.0.tgz"},"maintainers":[{"name":"thejameskyle","email":"me@thejameskyle.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/task-graph-runner-1.0.0.tgz_1514345618251_0.7605466642417014"},"directories":{},"publish_time":1514345618441,"_hasShrinkwrap":false,"_cnpm_publish_time":1514345618441}},"readme":"# task-graph-runner\n\n> Run async tasks with dependencies\n\n## Install\n\n```sh\nyarn add task-graph-runner\n```\n\n## Usage\n\n```js\nimport taskGraphRunner from 'task-graph-runner';\n\nlet graph = new Map([\n  [\"task-a\", [\"task-d\"]], // task-a depends on task-d\n  [\"task-b\", [\"task-d\", \"task-a\"]],\n  [\"task-c\", [\"task-d\"]],\n  [\"task-d\", []],\n]);\n\nasync function task(name) {\n  console.log(`start ${name}`);\n  let result = await exec(name);\n  console.log(`end ${name}`);\n  return result;\n}\n\nlet results = taskGraphRunner({ graph, task });\n// { safe: false,\n//   values: Map { \"task-a\" => \"result-a\", \"task-b\" => \"result-b\", ... } }\n```\n\nTasks will wait for their dependencies to run, but will be run with maximum\nconcurrency:\n\n```\nstart task-d\nend task-d\nstart task-a\nstart task-c\nend task-a\nstart task-b\nend task-c\nend task-b\n```\n\n#### Resolving cycles\n\nIf there are any cycles of dependencies (task-a depends on task-b which depends\non task-a), then `taskGraphRunner` will error unless `force: true` is passed:\n\n```js\nlet results = taskGraphRunner({ graph, task, force: true });\n```\n\nGraph cycles are resolved by picking a single item from the graph which has yet\nto be run that has:\n\n1. The fewest number of remaining dependencies (to reduce risk of missing dependencies)\n2. The highest number of remaining dependents (to increase chance of unblocking dependents)\n\n## API\n\n```js\ndeclare function taskGraphRunner<Item, Result>({\n  graph: Map<Item, Array<Item>>,\n  task: (item: Item) => Result,\n  force?: boolean,\n}): { safe: boolean, values: Map<Item, Result> };\n```\n\n#### `opts.graph`\n\nThis is a map of items to their dependencies. Items can be any type as long as\nthey are `===` to one another.\n\n```js\nopts.graph = new Map([\n  [1, [2, 3]],\n  [2, [4]],\n  [3, [4]],\n  [4, []],\n])\n```\n\n#### `opts.task`\n\nThis function gets called on every item in the graph. It should return a\npromise.\n\n```js\nopts.task = async function task(item) {\n  // ...\n};\n```\n\n### `opts.force` (default `false`)\n\n`taskGraphRunner` will error if it detects a cycle unless `opts.force` is\n`true` in which case it will try to break cycles by choosing a remaining item\nin the graph.\n\nIf it does detect a cycle, it will cause `res.safe` to be `false`.\n\n### `res.values`\n\nThis is a map of the items in the graph to their results from `opts.task`.\n\n```js\nres.values\n// Map { \"task-a\" => \"result-a\", \"task-b\" => \"result-b\", ... }\n```\n\n### `res.safe`\n\nIf the graph ran without any cycles `res.safe` will be `true`, otherwise it\nwill be `false`.\n","_attachments":{},"homepage":"https://github.com/thejameskyle/task-graph-runner#readme","bugs":{"url":"https://github.com/thejameskyle/task-graph-runner/issues"},"license":"MIT"}