pollize
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

pollize

NPM Version Node Version

poll until response

Installation

npm i pollize -S

Usage

import poll from 'pollize';
// for commonjs -> const pool = require('pollize').default

async function toCheck(i: number): Promise<number> {
  await sleep(200);
  const val = Math.random();
  console.log('got:', val, 'at', new Date());
  return i * val;
}

const result = await poll(toCheck,{
  onFulfilled: (result) => result > 8, // polling until return more than 8
  onReject: (result) => result < 0.5, // throw error once result less than 0.5
}, 10);
console.log('result:', result);

Options

const defaultPollOptions = {
  delay: 100, // delay time to start loop query
  interval: 1000, // execute interval
  timeout: 10 * 1000, // time after a long time and quit loop
};

Examples

examples are listed at examples

Todo

  • [ ] xx

Others

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i pollize

Weekly Downloads

0

Version

1.0.3

License

MIT

Unpacked Size

9.78 kB

Total Files

5

Last publish

Collaborators

  • cooperhsiung