pollize
v1.0.3
Published
poll until response
Downloads
2
Readme
pollize
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