@avinlab/repeat
Make repeat actions easily.
Install
# Yarn
yarn add @avinlab/repeat
# NPM
npm install --save @avinlab/repeat
Usage
import 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();
API
Options
-
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.
Methods
-
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).
License
MIT © avin