sagastor
v1.1.1
Published
Agnostic library for creating scalable and fault-tolerant workflows.
Downloads
4
Maintainers
Readme
Sagastor
Agnostic library for creating scalable and fault-tolerant workflows. Build your workflow as a Redux-inspired reducer.
Installation
With yarn
yarn add sagastor
With npm
npm install sagastor
Usage
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
Contributing
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.