BackburnerJS / backburner.js

A rewrite of the Ember.js run loop as a generic microlibrary
MIT License
391 stars 80 forks source link

Thoughts on adding an onCancel hook in debounce? #100

Closed DougPuchalski closed 10 years ago

DougPuchalski commented 10 years ago

Would it make sense to allow debounce to trigger a hook on cancelled callbacks so that the app could, for example, abort ajax requests?

stefanpenner commented 10 years ago

interesting, wanna try a PR im curious

DougPuchalski commented 10 years ago

Certainly can (if I can get testem to work). I'm still trying to decide whether this makes sense to add to debounce or if it might be a another utility.

Given: the debounce function, which has a target function that's called after the timer event. Pending state of the target function would be tracked until it returns, or its promise resolves. While pending, if the debounce function is called again, it would call the onCancel hook and then reset the timer.

Effectively, it's like debouncing not only for the timer delay, but also for the time to resolve the request.

I'm trying to decide whether this belongs in debounce, another method, or at the app-level.

Thoughts?

stefanpenner commented 10 years ago

@aceofspades my first thought is a higher level abstraction thats app specific

stefanpenner commented 10 years ago

Im closing this issue, but we can continue the discussion.

DougPuchalski commented 10 years ago

I think I agree this doesn't belong with debounce, and easily done at the app level. Feels like there is a lower-level abstraction here for handling slow async requests such as ajax but not quite sure where it belongs.