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

1.0.0 • Public • Published

A simple promise based function repeater.

Example

import { repeat } from '@stater/repeat';

// Repeat console log 10 times.
repeat(console.log).repeat(10);

// Repeat console log until finished = true.
let finished = false;
repeat(rt => {
  console.log(rt);

  if (rt >= 10) {
    finished = true;
  }
}).every('5s').until(() => finished);

// Run maintenance checker every 5s.
let complete = false;
await repeat(async (rt) => {
  console.log(`[Retries: ${rt}] Checking maintenance state.`);
  complete = await server.checkMaintenance();
}).every('5s').until(complete);
console.log('Server maintenance completed!');

/@stater/repeat/

    Package Sidebar

    Install

    npm i @stater/repeat

    Weekly Downloads

    1

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    10.4 kB

    Total Files

    7

    Last publish

    Collaborators

    • mahdaen