@sprnz/repeat-until

1.1.0 • Public • Published

@sprnz/repeat-until

Repeatedly call a function until a promise resolves. It also returns the promise that was passed.

Usage

import repeatUntil from '@sprnz/repeat-until';

(async () => {
  let i = 0;
  const repeatFn = () => {
    i += 1;
    console.log(i);
  };
  const promise = new Promise(resolve => setTimeout(() => resolve('Hello'), 42));
  const result = await repeatUntil(repeatFn, 10, promise);
  /******
      The above will log to the console:
      0
      1
      2
      3
    ******/
  console.log(result); // 'Hello'
})();

Readme

Keywords

Package Sidebar

Install

npm i @sprnz/repeat-until

Weekly Downloads

13

Version

1.1.0

License

ISC

Unpacked Size

4.06 kB

Total Files

7

Last publish

Collaborators

  • asartalo