https://github.com/avin/repeat
Make repeat actions easily.
https://github.com/avin/repeat
Last synced: 6 months ago
JSON representation
Make repeat actions easily.
- Host: GitHub
- URL: https://github.com/avin/repeat
- Owner: avin
- Created: 2019-01-07T14:00:02.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-17T07:44:03.000Z (over 7 years ago)
- Last Synced: 2025-02-20T17:09:44.884Z (over 1 year ago)
- Language: JavaScript
- Size: 89.8 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# @avinlab/repeat 
> Make repeat actions easily.
## Install
```bash
# Yarn
yarn add @avinlab/repeat
# NPM
npm install --save @avinlab/repeat
```
## Usage
```js
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](https://github.com/avin)