This library aids in writing and executing workflows asynchronous tasks with interdependencies, with a focus on well-typed task definitions.
import { workflowBuilder, concurrentExecutor } from "async-task-graph"
const builder = workflowBuilder<{
context: { hello: string }
returns: {
foo: string
bar: number
}
}>()
builder.addTask({
id: `foo`,
dependencies: [],
run: ({ context }) => {
return Promise.resolve(JSON.stringify(context))
},
})
builder.addTask({
id: `bar`,
dependencies: [`foo`],
run: ({ getTaskResult }) => {
const str = getTaskResult(`foo`)
return Promise.resolve(str.length)
},
})
const { emitter, runWorkflow } = builder.build(concurrentExecutor())
emitter.on(`taskFinish`, ({ id, result }) => {
console.log(`${id} returned ${JSON.stringify(result)}`)
})
await runWorkflow({ hello: `world` })