sagastor

1.1.1 • Public • Published

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.

License

MIT

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i sagastor

      Weekly Downloads

      10

      Version

      1.1.1

      License

      MIT

      Unpacked Size

      7.49 kB

      Total Files

      6

      Last publish

      Collaborators

      • aabbdev