Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async Set Interval #1506

Closed
pacoccino opened this issue Dec 23, 2017 · 1 comment
Closed

Async Set Interval #1506

pacoccino opened this issue Dec 23, 2017 · 1 comment
Labels

Comments

@pacoccino
Copy link

pacoccino commented Dec 23, 2017

This is not a bug, but a feature request.
I already implemented that feature on my own, but I think would be great to have it in async module.

The native setInterval is not well-suited for async methods and error handling.

I propose a new setIntervalAsync method that would handle async functions, correctly run and stop intervals and correctly handle errors.
Prototype: setInvervalAsync(asyncFunction, delay, onError). Returns clear function.

Behaviour:

  • Wait that asyncFunction finishes to run the interval.
    If function takes 100ms to finishes and delay is 50ms:
    0 ms: start fn
    100ms: end fn, start interval
    150ms: start fn again
    250ms: end fn

  • If asyncFunction throws, call onError callback with the error. Continues the interval and run again asyncFunction after interval.

  • When clear function is called, returns a Promise that is resolved when current fn execution is finished. Do not run again interval.

I'll create a package for my implementation soon and share it here.

@aearly aearly added the feature label May 21, 2018
@aearly
Copy link
Collaborator

aearly commented Jul 9, 2018

Let us know when you have an example package, we could link it in the readme.

@aearly aearly closed this as completed Jul 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants