bjoerge / debounce-promise

Create a debounced version of a promise returning function
MIT License
241 stars 27 forks source link

add maxWait option #18

Open pbadenski opened 5 years ago

pbadenski commented 5 years ago

Implements #11

bjoerge commented 5 years ago

Hey and thanks @pbadenski. I like the idea, but wondering if flush should be scheduled using a setTimeout instead? If I understand your implementation correctly, the debounced function will now have to be called in order to check for maxWait to have passed, but maxWait may have already passed at that time.

e.g. using wait=1000, maxWait=4000

time (ms) ->
0       1000     2000     3000     4000     5000
|--------|--------|--------|--------|--------|
x   x  x  x    x    x  x    x   x x    x
                                    ^--- should have flushed here
                                       ^--- but will flush here