Agnostic library for creating scalable and fault-tolerant workflows. Build your workflow as a Redux-inspired reducer.
With yarn
yarn add sagastor
With npm
npm install sagastor
import { BuilderWithTopic } from "sagastor";
const saga = new BuilderWithTopic("AUTH", {
initial: {
invoke(event){
console.log(`INITIAL Hello ${event.name}`);
return { ...event, message: `Hello ${event.name} from initial` };
},
rollback(){
console.log('INITIAL backward', event);
}
},
processing: {
invoke(event){
console.log('PROCESSING forward', event);
throw new Error('test');
},
rollback(event){
console.log('PROCESSING backward', event);
return { ...event, message: `hello ${event.name} from rollback`};
}
}
});
let [topic, event] = [
"initial",
{ name: "Lucas" }
]
while(true){
const result = await saga.execute(topic, event);
if(!result) break; // end
[topic, event] = result;
}
For more examples
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.