sindresorhus / debounce

Delay function calls until a set time elapses after the last invocation
Other
798 stars 80 forks source link

Ability to force execution #16

Closed p closed 7 years ago

p commented 7 years ago

This PR adds an option to force execution of any scheduled invocations.

Use case: I have a map that the user can move around, and the center is updated on the server with each move. This update is debounced. The user can also load a different object into the map in which case I want to immediately flush pending moves for the old object.

vendethiel commented 7 years ago

It sounds counter-intuitive to me. I think force should always call the function, even if there's no timeout going on.

p commented 7 years ago

It may be helpful to think of force as a flush method on a file. Both are called from different contexts than debounce itself/write. The code that does force/flush does not have arguments for the debounce/write call.

p commented 7 years ago

Maybe a different name would be more appropriate, open to suggestions.

vendethiel commented 7 years ago

I'm inclined to call it reset.

p commented 7 years ago

I don't think one would expect reset to perform an action...

p commented 7 years ago

How about flush?

vendethiel commented 7 years ago

Go for it

vendethiel commented 7 years ago

Thanks!

hotforfeature commented 7 years ago

This feature was added 4 months ago, any plans to publish to npm?

mysticatea commented 7 years ago

@vendethiel Could you publish this feature?

vendethiel commented 7 years ago

@mysticatea I don't have npm access to this package...

jscheid commented 7 years ago

@vendethiel do you know who does, or when a release is planned?

vendethiel commented 7 years ago

I don't know

p commented 7 years ago

@stephenmathieson Are you able to publish a new version on npm with this PR included?

stephenmathieson commented 7 years ago

Yep! I can publish in the morning

stephenmathieson commented 7 years ago

1.1.0