1.1.1 • Published 2 years ago

sagastor v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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

1.1.1

2 years ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago