Giter VIP home page Giter VIP logo

promise-poller's Issues

Interval option not working

When I pass 60000 as the interval, it calls my function every 10 seconds (estimate) instead of every 60 seconds.

  promisePoller({
        taskFn: pollTask,
        interval: 60000, // milliseconds
        retries: 3,
        shouldContinue: () => shouldContinue,
      });

masterTimeout value is not taken into account (globalTimeout is used)

I've try a stupid test by setting the masterTimeout value and it seems not taken into account, there is a kind of timeout that occur but not at the time specified in masterTimeout value
I've look at the code, when masterTimeout then it create a setTiemout with the field options.globalTimeout:

if (options.**masterTimeout**) { setTimeout(() => reject('master timeout'), options.**globalTimeout**);

Exponential backoff support

Retrying after a fixed interval may not be ideal in some applications. Extending this package to also support using exponential backoff would be helpful.

Short circuit on certain exception types

Some exceptions may be due to a condition that won't change over the course of polling - for example, a syntax error.

The idea would be, if we fail on one of these types of exceptions, to stop polling early since we won't have any different results.

Cannot cancel from within promise

You may want to cancel the polling early. For example, if the poll fails because of an invalid password, that's not likely to change, so it would be a waste of time to continue to poll. To cancel polling early, return false from the task function instead of a promise.

The use cases I have had so far for polling all involve async tasks, which cannot cancel the polling operation if they encounter an error that should be fatal, because they can't make the task function return false instead of a promise.

One possibility would be to add a unique sentinel value/error type for cancelation.

A possible workaround is to maintain a flag in the enclosing scope that allows cancellation on the next invocation, but this isn't as nice as canceling immediately especially if the interval is high.

Timeout does not work

The timeout-functionality seems to be broken:

require('promise-poller')({
  taskFn: () => {
    console.log('polling...');
    return Promise.reject();
  },
  interval: 10,
  timeout: 1000,
})
.then(() => console.log('success'))
.catch(() => console.log('failed'));

This will log "polling..." 5 times (which seems to be the default) and then fails. When adding retries: Infinity, it keeps polling infinitely.

Any idea what's up?

Add "total poll" timeout

Currently, the timeout option sets the timeout for each individual poll. It might also be handy to have a timeout for the entire poll operation.

So, for example:

timeout: 10000 means "every time you poll, reject the promise for that poll iteration if it's not resolved after 10 seconds.

totalTimeout: 10000 means "while polling one or more times, reject the master promise if there isn't a successful poll after 10 seconds."

No way to cancel with specific error message

I'm wanting to make a function that polls a GitHub commit status until my CI build has finished. To do this with promise-poller, I have the following code:

taskFn: () => this.repos.owner(owner).repo(repo).commits.ref(ref).status().then(({state}) => {
  if (state === 'failure') return false
  if (state === 'pending') throw new Error('commit is still pending')
}),

This is kind of backwards, at least for my use case, because I can't return a "build failed" error if state === 'failure'. It would be better if I could return false when state === 'pending' and throw an error when state === 'failure'.

But really, considering that one might want to poll and eventually resolve to a boolean value, I think it would be best to support isDone and shouldContinue functions that default to the current behavior.

Add timeout support

There may be use cases where a poll should fail after a given timeout if the promise isn't settled by then.

Passing arguments to taskFn

Apologies if I missed it in the documentation, but is it possible to pass arguments to the taskFn? Thanks for your work on this project!

Clear masterTimeout interval

masterTimeout is implemented using a setInterval that is not cleared when the master promise resolves. If the timeout is long and the program is supposed to exit after polling completes, the interval will prevent the Node process from exiting.

Errors ignored when setting timeout

When setting the timeout property any error caused by the poll task will be ignored.
The poller will wait for the timeout to run out and swallow the actual error message.

Is being addressed in #25

@joeattardi could you please approve the PR to be merged? Thanks ๐Ÿ™

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.