0.1.1 • Published 9 months ago

@knicola/repeat v0.1.1

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

@knicola/repeat

Repeats the given task for a certain amount of times or forever. Useful for repetative tasks, such as polling.

Install

Using npm:

$ npm install @knicola/repeat

Using yarn:

$ yarn add @knicola/repeat

Usage

import { repeat, RepeatOptions, RepeatTask } from '@knicola/repeat'

// default options
const options: RepeatOptions = {
    timeout: 3000,
    startOnInit: true,
    runOnStart: true,
    maxRuns: Infinity,
    maxFailures: Infinity,
}

// to be populated by the repeated task
let status: string = 'n/a'

// the task to repeat
const task: RepeatTask = async () => {
    status = await axios.get('https://example.com/api/status')
}

// initialize the repeat operation
const op = repeat(task, options)

// check if task is running
console.log(op.isRunning) //=> true

// cancel the task
op.stop()

License

This project is open-sourced software licensed under the MIT license.