Run an Async Task Graph
Hard · Async
Write runGraph(tasks) that runs async tasks with dependencies as early as possible and resolves with an Outcome for every task id.
- Start a task as soon as all of its deps are done. Tasks that become ready at the same moment start in the order of Object.keys(tasks). Never wait for unrelated tasks.
- run(inputs) receives the value of each dependency, e.g. { a: 1, c: 12 }.
- If run rejects or throws, the task is failed with the error message. A task that depends on a failed or skipped task is skipped and never runs.
- Resolve once every task has an outcome. Dependencies always exist and never form a cycle.
The driver runTasks(specs) is already written: each task waits delay ms and returns add plus the sum of its inputs. It also returns the order of the start/end events.
Next: Parallel Task Scheduler