Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »

node-transactions

1.1.1 • Public • Published

Node Transactions

Build Status Coverage Status npm

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',
    perform: function *doYourJob() { ... },
    rollback: function *revertChanges() { ... }
};

Launching

When you have prepared bunch of tasks and context - simply launch Transactions engine:

let result = yield new Transactions([task, nextTask, ...], context);

Result

result would have next properties:

  1. result.success - enum: [true, false]
  2. result.context[task.name].performResult - the result of successful execution of tesk.perform
  3. result.error - the first and only task.perform error (only if result.success === false)
  4. result.rollbackErrors - array of possible task.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:

function *storeTransactionState(name, phase, context) { ... }
context.storeTransactionState = storeTransactionState;

Issues

Any bugs or improvements are appreciated and could be posted at https://github.com/ceoworks/node-transactions/issues

install

npm i node-transactions

Downloadsweekly downloads

6

version

1.1.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability