#sequence-stepper
A small lib for asynchronous control stack of functions. It can start executing on any step in queue to the end.
##Usage
###class Stepper
Creating a stepper queue
import {Stepper} from 'stepper';
let stepper = new Stepper([
(step, data) => step.next(++data),
(step, data) => data > 2 ? step.next(data * 2) : step.reject('fail'),
(step, data) => console.log(data)
]);
Start executing
stepper.next(data);
You can return to the backward step with same code (backward step dos't execute)
stepper.prev();
Execute step after said stepDescriptor
stepper.next(data, stepper[2]);
Executing on some step in queue:
let savedStepDescriptor;
let stepper = new Stepper([
(step, data) => {...},
(step, data) => {
...
savedStepDescriptor = step;
step.next();
},
(step, data) => {...}
]);
stepper.next()
savedStepDescriptor.next()
###function sequence
Its help you to make a function thats launches a queue to the end. You can make with that simple functional conveyors.
import {sequence} from 'Stepper'
let queue = sequence([
(step, data) => step.next(data * 2),
(step, data) => step.next(data + 4),
(step, data) => data * 3,
])
let result = queue(5);
You can add asynchronous behavior into steps
let queue = sequence([
(step, data) => setTimeout(() => step.next(data + 11), 100),
(step, data) => console.log(data * 2),
])
queue(10);