{"_id":"task-graph-runner","_rev":"5-0ae52a2f7c3b30170f5cf0f4a51bb834","name":"task-graph-runner","description":"Run async tasks with dependencies","dist-tags":{"latest":"1.0.3"},"versions":{"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":{"integrity":"sha512-EpHjg5DR9PQKlFDJrgTdmthTyEjgN6Z02Ecy22CEmgoD+mWgQXQSaW12lKJm2N5kCDBhD7UUBkoQ7tZ9ChwSag==","shasum":"d80ccd2df5321154206e51ca3a2edb4e8d7ae6d6","tarball":"https://registry.npmjs.org/task-graph-runner/-/task-graph-runner-1.0.0.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCLFaoQd0r8YQhwovSuSC7DighYoSSW7DiCwoWeqXIS1QIgJvyO2Di0BsLFT3E5W/GJZp8Tg5gv/aMGvintxEkTWSs="}]},"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":{}},"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":{"integrity":"sha512-BrYisJpyKsz0vpA88vSgXhxKnbsbttep9WacXIZMhPrzr6vf31nNyulM/yZ+7lAddEGYrArGlaxUEZV+AAt6mw==","shasum":"321eb31f06b915dd9504e369187d11c14ddc6b26","tarball":"https://registry.npmjs.org/task-graph-runner/-/task-graph-runner-1.0.1.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFq1TYAtu+gthSSzH5Q0rKiE+NqRopTUBnHQI2GfSF9lAiEA3nWGRU/EXOwkPk6s5ISQ7J8DAJ6rZe4lEouMNbI74HA="}]},"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":{}},"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":{"integrity":"sha512-ua9VE+cJ4LVT1TcSl31vFi50NaPFFyAUdjsqpXuooe8AZm1nBP443swgNRjA3CxatSZKtP6vacErIbClMSCmTA==","shasum":"dfc73e4f92d74b974a854ccd3b2a8c7f1fbf4137","tarball":"https://registry.npmjs.org/task-graph-runner/-/task-graph-runner-1.0.2.tgz","fileCount":4,"unpackedSize":6719,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHwTKANOQtoGi+C0o0GiwqLE31Eewsvjzjtd94oaJPZyAiAPxGlzdb/+61ztikTyaD1O8iGOj6QraX/fJ2OhxvneeQ=="}]},"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},"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":{"integrity":"sha512-aC70bepv1j9jXX70nzolNvnHJvD4A3WtU4lQ1HEjgTS8rgnRXoUUq+xl9hZ1hKYXxVwElZXmUUMxpzDC6R0mRg==","shasum":"73b2cd380cef6f51b8179b0d1da4bb7c356b03bf","tarball":"https://registry.npmjs.org/task-graph-runner/-/task-graph-runner-1.0.3.tgz","fileCount":4,"unpackedSize":6728,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJd985/CRA9TVsSAnZWagAABuAP/3CNrVLjqj7dfgNwM7YT\ncKVXQXHmSVEGYInePt1AsW/uCYY8j/dzKVZtKHpBiclWlt3fCT70ZotbJwAB\nVFX6G3Bh+/TrWdPjLNnpywTv9kyzczsusFqFDXba3lJY1kSpCokNh/YZkNqr\ncMiOF/J7sPvJW4ysSanGwP9xNPvnhUaCBIioWcZc/KVWfBlUMXVELDMH56bi\nouSTx9KBiRMDTfpKIs27nzPonIUqk1BOo/Cic6Q61e/A1ZpBDYRQdDJflEPN\nZu/B/DkL6IN7khA6K1QfmDR42tFfg829V/WJvTpJPDhpn+fapLjkqksJftVe\nLQ69a9mpbV7Dv7E7hLcqklhwT7LudXZOuhHK9N+knBbu2WZX0Uz1cJXAPGco\nTjv9w+AzIyXVOFRpMPYIBfeZQ3xKN7MeRfSnEVtzjBQziXp/bjKlLqA0eSMy\no8aRD12yCWLgDrLiPT5hyJlpYOfYpyX03z3mCh9P3kXYw027YNo03tyOJQ3g\nQbvugZsR7uLZOuZbznm7U2cCCkTcQuCtqhsDW1BJZYsTFqWmIb7xa9URDRl7\neBEjMQ7cxni3JM/CS4+NmH5J0JtafIFs9TfjsEiaqICsj+3Fyu9/NXn1YTkz\nPtixLdnfPoDekt1tw9njvsDS+O2V8cKzhUEHoXNQpo79Dsd8yBMHbUfwAwre\n4hAH\r\n=ZaeM\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCID54l+0slUa6s/Jni5X+Fsn+2Ye3Uv4iRe7UMSjy7StxAiBPIsgVhygYGyzCcUAGqxuA24TzB7D6h+MjekQy1BFxtA=="}]},"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}},"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","maintainers":[{"name":"thejameskyle","email":"me@thejameskyle.com"}],"time":{"modified":"2022-05-19T10:18:40.304Z","created":"2017-12-27T03:33:38.441Z","1.0.0":"2017-12-27T03:33:38.441Z","1.0.1":"2017-12-27T06:04:56.433Z","1.0.2":"2018-03-08T20:32:25.077Z","1.0.3":"2019-12-16T18:35:43.437Z"},"homepage":"https://github.com/thejameskyle/task-graph-runner#readme","keywords":["graph","adjacency","list","tasks","priority","priorities","sort","dependencies","topological","topo","sequencer","task","runner"],"repository":{"type":"git","url":"git+https://github.com/thejameskyle/task-graph-runner.git"},"author":{"name":"James Kyle","email":"me@thejameskyle.com"},"bugs":{"url":"https://github.com/thejameskyle/task-graph-runner/issues"},"license":"MIT","readmeFilename":"README.md"}