Skip to content

zweifisch/reverflow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

reverflow

https://img.shields.io/npm/v/reverflow.svg?style=flat https://img.shields.io/travis/zweifisch/reverflow.svg?style=flat

reversible flow for building robust application with javascript

  • explicit(serial/concurrent) flow construction
  • multi step rollback made easy
  • works with both sync and async(returns promise) functions

usage

for nodejs < v6 require the transpiled version

var reverflow = require("reverflow/legacy");

a simple serial flow

graph/compositing-1.png

const {serial} = require('reverflow');
serial(x => x + 1, x => x * 2)(1).then(console.log);
4

creating flow by composition

graph/compositing-2.png

const {serial, concurrent} = require('reverflow');
serial(concurrent(serial(x => x + 1, x => x * 2),
                  x => x * 3),
       ([x, y]) => x + y)(1).then(console.log);
7

rollbackable serial operations

graph/serial.png

when C fails, B should be rolled back, then A.

reverflow does this auotmatically, you can make an operation rollbackable with the rollbackable function

import {serial, rollbackable} from reverflow

serial(rollbackable(A, undoA),
       rollbackable(B, undoB),
       rollbackable(C, undoC))(input);

rollbackable concurrent operations

graph/concurrent.png

when C fails, B and D should be rolled back, then A.

import {rollbackable, serial, concurrent} from reverflow
serial(rollback(A, undoA), concurrent(rollbackable(B, undoB),
                                      rollbackable(C, undoC),
                                      rollbackable(D, undoD)))(input);

miscs

passing param to the rollback function

rollbackable(input => save({id: uuid.v4()}), ({id}) => remove(id));

arrays can be passed to serial and concurrent

serial(a,b,c) is equivelant to serial([a, b, c])

normal functions can be passed to serial or concurrent

About

reversible flow for building robust application with javascript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published