Make repeat actions easily.
# Yarn
yarn add @avinlab/repeat
# NPM
npm install --save @avinlab/repeatimport repeat from '@avinlab/repeat';
const repeatAction = repeat({
action: counter => {
console.log(counter);
},
delay: 500,
firstTimeDelay: 1000,
skipFirst: true,
});
// Start interval actions
repeatAction.start();
// Stop interval actions
repeatAction.stop();action(Function) - Interval function. Params:counter- call action index number.delay(Number) - Sleep time in ms between actions.firstTimeDelay(Number) - First time sleep period in ms.skipFirst(Boolean) - Skip first time action call.times(Number) - Repeat N times.
start()- Start repeat actions.stop()- Stop repeat actions.pause()- Pause repeat actions (without reset counter and don't touch firstTimeRun flag).resume()- Resume repeating after pause.updateDelay(newDelay)- Update option delay value without restart (update with next tick).
MIT © avin