JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q19464F
  • License MIT

A small lib for asynchronous control stack of functions

Package Exports

  • sequence-stepper

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sequence-stepper) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

#sequence-stepper

The small lib for the asynchronous control of stack of functions. It can start an execution at any step in a queue till the end.

##Installation

npm install --save sequence-stepper

##Usage

###class Stepper Creation 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 an execution

stepper.next(data);

You can step back with the same code (backward step doesn't execute)

stepper.prev();

Execute a step after stepDescriptor

stepper.next(data, stepper[2]);

Execution on some step in queue

let savedStepDescriptor;

let stepper = new Stepper([
  (step, data) => {...},
  (step, data) => {
    //some behavior
    ...
    savedStepDescriptor = step;
    step.next();
  },
  (step, data) => {...}
]);

stepper.next()//execute queue to the end

savedStepDescriptor.next()//execute queue from saved step to the end;

###function sequence Its help you to make a function thats launches a queue to the end. You can make it with this 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);//result === 42

You can add an asynchronous behavior into a steps

let queue = sequence([
  (step, data) => setTimeout(() => step.next(data + 11), 100),
  (step, data) => console.log(data * 2),
])

queue(10);//output 42 in console after 100ms