Node Transactions
Usage
Examples of code are shown in test/index.spec.js
In case you are already using generators-yields
functions - you are completely set up.
If you are writing classic async-callback
code - you would probably like to look at thunkify
package.
API
Context
The first thing you need is the context
object, which would have all required data for tasks execution.
let context = lannisters: false starks: true
Task
The main brick of the Node Transactions
module is a task
:
task = name: 'westeros' { ... } { ... };
Launching
When you have prepared bunch of tasks
and context
- simply launch Transactions engine:
let result = task nextTask ... context;
Result
result
would have next properties:
result.success
-enum: [true, false]
result.context[task.name].performResult
- the result of successful execution oftesk.perform
result.error
- the first and onlytask.perform
error (only ifresult.success === false
)result.rollbackErrors
- array of possibletask.rollback
errors
Storing transactions' data
To store the intermediate transaction's data, you need to pass into the context your own implementation of storeTransactionState, which would get next args:
{ ... }contextstoreTransactionState = storeTransactionState;
Issues
Any bugs or improvements are appreciated and could be posted at https://github.com/ceoworks/node-transactions/issues