lil-saga
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Lil' Saga

Latest NPM release TravisCI Build Status

lil-saga is a small library to assist in use of the saga pattern.

Usage

lil-saga accepts a generator which may yield a Saga, a Promise, or an array containing a mix of Sagas and Promises.

If an array is yielded, the actions (and any subsequent rollbacks), will be performed concurrently.

If an error occurs during execution, any previously executed Sagas will have their undo performed, in reverse order of execution.

Example

import lilSaga from 'lil-saga';
 
await lilSaga(function*() {
  let promiseYieldingFunctionResult = yield promiseYieldingFunction();
 
  let anotherPromiseYieldingFunctionResult = yield {
    do() {
      return anotherPromiseYieldingFunction();
    },
 
    undo() {
      return anotherPromiseYieldingFunctionReverse();
    }
  };
 
  let [
    thing1,
    thing2,
    thing3
  ] = yield [
    doThing1(),
    {
      do: () => doThing2(),
      undo: () => undoThing2()
    },
    doThing3()
  ];
});

Readme

Keywords

none

Package Sidebar

Install

npm i lil-saga

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

12 kB

Total Files

5

Last publish

Collaborators

  • kturney