1.0.0 • Published 5 months ago

runner-z v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

  • task runner with timeout.

Installation

install via npm:

npm i runner-z

Usage

Properties

PropertyData TypeDefault ValueProperty Unit
fallbackcallback/promisefunc({ iteration,isLastTime })
delaynumber1000ms
maxIterationnumber0-

Guideline

/**
 Props
+ maxIteration
    maxLoop = 0: infinite
    maxLoop > 0: limit
+ delay: default 1000ms
+ fallback: callback or promise
/**
********************************
**** update
+ setMaxIteration(maxIteration: number);
+ setDelay(delay: number);
+ setCallback(callback: TPFallback);

********************************
**** execute basic
+ start(): start now
+ stop(): stop now
+ restart()

********************************
**** execute
+ startAfter(): start after delay (props)
+ startAfterTimeout(time: number) start after time
ex:
- delay: 5000
- startAfterTimeout(3000)
=> we can start after 3000ms, then delay repeat 5000ms

********************************
**** get status
+ isRunning(): boolean;
+ getTimes(): number;
*/
sync function
import { Runner } from 'runner-z';

const runner = new Runner({
    fallback: params => {
      const { iteration } = params;
      console.log(runner.isRunning());
    },
    delay: 5000,
    maxIteration: 3,
  });
runner.start();
async function
import { Runner } from 'runner-z';

const runner = new Runner({
    fallback: async params => {
      const { iteration } = params;
      const results = await fetch(
        `https://jsonplaceholder.typicode.com/todos/${iteration}`,
      );
      const info = await results.json();
      console.log(info);
      console.log(runner.isRunning());
    },
    delay: 5000,
    maxIteration: 3,
  });

runner.start();

License

MIT