JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q19462F
  • 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

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) => {
    //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 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);//result === 42

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);//output 42 in console after 100ms