loop-controller
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

Loop Controller

Controls serial execution of promises

Installation

npm i loop-controller

Usage

import { LoopController } from "loop-controller";

//create a loop controller, that runs five iterations.
//It starts execution automatically.

const lc = new LoopController({
  initialArray: [1, 2, 3, 4, 5],
  makePromise: (index) => {
    console.log("iteration: " + index);
    return Promise.resolve();
  },
});

// at any point call

lc.pause();
lc.resume();
lc.setArray();
lc.prependArray();

testing

The underlying waiter is exposed, to it's possible to 'hook' into the loop controller's transitions.

//await first iteration finishes, and pause it.

lc.waiter.await("iteration-done").then(() => {
  //LoopController will receive a pause command in a certain state.
  lc.pause();
});

This way we can 'inject' actions when LoopController makes state transitions or emit events. It's a powerful way to do white-box testing.

Known issues

Related work

License

MIT

Package Sidebar

Install

npm i loop-controller

Weekly Downloads

8

Version

1.1.0

License

MIT

Unpacked Size

15.7 kB

Total Files

8

Last publish

Collaborators

  • jawis