concurrent-octopus
v1.0.3
Published
nodejs work flow
Downloads
3
Readme
Octopus
Use
const { CO, EVENTS } = require("concurrent-octopus");
const flow = new CO();
const task = flow
.add(({ next, error, stop, id, name, data }) => {
Promise.resolve(data).then((res) => {
next(res + 1);
});
})
.add(({ next, error, stop, id, name, data }) => {
setTimeout(() => {
next(data + 1);
}, 1000);
});
// event listener
task.events.on(EVENTS.START, ({ data }) => {});
task.events.on(EVENTS.STOP, ({ data }) => {});
task.events.on(EVENTS.ERROR, ({ data }) => {});
task.events.on(EVENTS.FINISHED, ({ data }) => {});
task.events.on(EVENTS.BEFORE_RUN_TASK, ({ data }) => {});
task.events.on(EVENTS.TASK_FINISHED, ({ data }) => {});
task.events.once(EVENTS.START, ({ data }) => {});
task.events.once(EVENTS.STOP, ({ data }) => {});
task.events.once(EVENTS.ERROR, ({ data }) => {});
task.events.once(EVENTS.FINISHED, ({ data }) => {});
task.events.once(EVENTS.BEFORE_RUN_TASK, ({ data }) => {});
task.events.once(EVENTS.TASK_FINISHED, ({ data }) => {});
// task runner start
task.start(1, ({ data }) => {
console.log(`All task finished, data is: ${data}`); // 3
});
const task2 = task.start(10, ({ data }) => {
console.log(`All task2 finished, data is: ${data}`); // 12
});