bjoerge / debounce-promise

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

Single call option? #12

Closed sprat closed 5 years ago

sprat commented 6 years ago

I would like to debounce a function returning a promise but also limit the concurrent calls of my function to 1. That is, if a previous promise is still running after the debounce delay is reached, delay again and again... until the last promise finish and the debounce delay is expired (no other calls occured during the waiting time).

In fact, my use case is an async database update: i don't want to update the database too often, and not concurrently either, but I want the last call to be performed so that the latest data goes into the database.

slorber commented 6 years ago

isn't this already the default behavior?

sprat commented 6 years ago

It was not the case in the application I was developping, as far as I remember. But I have no test/repro case to provide unfortunately.

bjoerge commented 5 years ago

If I understand your question correctly, @slorber is correct in that this is the default behavior. Feel free to reopen or create a new issue if this is not the case.

ziemkowski commented 5 years ago

I'm seeing what @sprat saw when I add a 3 second sleep to the remote endpoint being accessed by an autocomplete input using debounce-promise set to 200ms:

image

I'd open a new ticket if I had a bit more time so I could produce a minimal test, but I don't right now. It's very close to the first readme example with fetch().

SimonKlausLudwig commented 4 years ago

I have the same problem. I expected that the debounce function waits for a promise to finish before calls the function again to prevent concurrent changes for example.

Isn't this the case ?

I 'fixed' this by using a queu (https://github.com/sindresorhus/p-queue). Would be great if this would be build in.