Commit 8c4d6ea2 authored by Paul Slaughter's avatar Paul Slaughter

Update simple_poll with timeout 0 and object arg

**Why timeout 0?**
Sometimes we want to poll without timing out.

**Why an object argument?**
It's helpful to pass these extra properties by name.
`simplePoll(cb, { timeout: 0 })` is nicer than
`simplePoll(cb, undefined, 0);`
parent f396ebe4
export default (fn, interval = 2000, timeout = 60000) => {
export default (fn, { interval = 2000, timeout = 60000 } = {}) => {
const startTime = Date.now();
return new Promise((resolve, reject) => {
const stop = arg => (arg instanceof Error ? reject(arg) : resolve(arg));
const next = () => {
if (Date.now() - startTime < timeout) {
if (timeout === 0 || Date.now() - startTime < timeout) {
setTimeout(fn.bind(null, next, stop), interval);
} else {
reject(new Error('SIMPLE_POLL_TIMEOUT'));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment