async-rollback
A simple util to make rollback easy in complex nested promises.
Every now and then we have a problem wherein db/micro service call depends on each other For eg.
{ return // call some async api/db call} { return // call some async api/db call}
This seems fine but over here we forgot if updateSomeDoc3 fails we need to revert updateSomeDoc2 changes as well as updateSomeDoc1 update, this library provides a much better interface to solve this issue.
Features
- Can be used to nest multiple update/create call which depend on each other
- Can be used to rollback update/create calls using update/delete call
- transaction function can set what it needs to give child just like async waterfall
- rollback receives own params and it's transaction response.
Example
$ npm i$ cd examples$ node basic // For basic nest calls$ node rollback // know how rollback happens$ node rollbackWithTransaction // rollback using transaction response
Installation
npm install async-rollback --save
Usage
; const updateObj = transaction: Promise params: {} rollback: Promise params: {} transaction: Promise params: {} rollback: Promise params: {} ; ;//...
Contributing
If you'd like to see something added or changed to this module please open a new GitHub issue. Pull requests are always welcome.