Skip to content

cooperhsiung/pollize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

poll until response

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published