Simple utility for orchestrating interdependent concurrent tasks in TypeScript
npm install contrepointSimple utility for orchestrating interdependent concurrent tasks in TypeScript.
``bash`
npm i contrepoint
`typescript
import { createRunner } from "contrepoint";
// Create a runner
const runner = createRunner()
.register({
name: "first",
run: async () => "Hello",
})
.register({
name: "second",
run: async ({ outputs }) => {
// Access results from other tasks
const firstResult = await outputs.first;
return ${firstResult} World;
},
});
// Run with error handling (Promise.allSettled)
const results = await runner.run();
// {
// first: { status: 'fulfilled', value: 'Hello' },
// second: { status: 'fulfilled', value: 'Hello World' }
// }
// Run where all tasks must succeed (Promise.all)
const allResults = await runner.all();
// { first: 'Hello', second: 'Hello World' }
// You can also pass input to all tasks
const runnerWithInput = createRunner
name: "task",
run: async ({ input }) => Got input: ${input},
});
await runnerWithInput.run("my input");
`
`typescript
import { createTask, createRunner } from "contrepoint";
const first = createTask({
name: "first",
run: async () => "Hello",
});
const second = createTask({
name: "second",
// Declare dependencies by typing the context
run: async (ctx: Context
// Full type safety!
const firstResult = await ctx.outputs.first;
return ${firstResult} World;
},
});
// This work
const runner = createRunner().register(first).register(second);
// If you try to register second before first, you will getfirst
// a type error because 's output will be missing from second's context``
const runner = createRunner().register(second).register(first);