@knicola/repeat
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

@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.

Package Sidebar

Install

npm i @knicola/repeat

Weekly Downloads

1

Version

0.1.1

License

MIT

Unpacked Size

19.5 kB

Total Files

9

Last publish

Collaborators

  • knicola