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

Add a new run loop function to coalesce requests until timer ends #127

Closed
aaronbhansen opened this issue Jan 20, 2015 · 4 comments
Closed

Comments

@aaronbhansen
Copy link

We are needing a new run loop function that works similar to debounce, but functions a little differently.

How it would work is as follows:

  • A call is made to the coalesce function and the method is run immediately. A timer is also started for that method signature.
  • Each additional call cancels the current timer and creates a new one (like debounce). A counter is also incremented for each time the method signature is called.
  • When the timer is complete, if the counter is greater than 0 (meaning the method was called more than once during the timeout period), the method is called a second time.

Our use case is, we have a web socket that pushes data updates to the front end on any backend change. We want the first data update to fire immediately, but then coalesce all the remaining data updates until the timer expires. We find that we are updating the data several times on the backend (with various backend processes), but want to limit the number of requests on the front end until we know the changes are complete.

Debounce and throttle don't meet this requirement. I looked at extending backburner locally, but that would require rewriting and implementing many of the internal functionality to add this new method. It would be much easier to add it in backburner directly.

I'm adding an issue here, to see if I created a pull request, if this is something that you could see being used else where and would be pulled into backburner to make available for ember?

@mixonic
Copy link
Collaborator

mixonic commented Jan 20, 2015

This sounds like debounce with immediate. See:

Passing true for immediate runs the method right away, then debounces the 2nd to the nth calls.

@aaronbhansen
Copy link
Author

It is close, but the difference is, if you set immediate to true, it only runs the method once and then debounces until the timer is cleared. I want two calls to the method, once immediately, and once when the timer clears if the method was called more than the initial immediate time.

Using debounce with immediate, if the method was called 5 times before the timer cleared, the method would be called immediately and then not again until the timer cleared.

Using the proposed coalesce, if the method was called 5 times before the timer cleared, the method would be called immediately, and then once again when the timer cleared. Coalescing all the calls after the first into one final call at the end.

@runspired
Copy link
Contributor

@aaronbhansen you get this coalescing behavior using requestAnimationFrame instead of setTimeout: see #163

@rwjblue
Copy link
Collaborator

rwjblue commented Jan 21, 2018

Closing this as it seems to have gone stale... I think in general, we would entertain a PR but I'm not certain that the use case for a specific coalesce method is general purpose enough to warrant inclusion.

IMHO, a better path forward would be to distill what functionality would be required from Backburner to allow this to be relatively easily implemented in user-land?

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

No branches or pull requests

4 participants