szchenghuang / debounce-async Goto Github PK
View Code? Open in Web Editor NEWA debounce function that delays invoking asynchronous functions.
License: MIT License
A debounce function that delays invoking asynchronous functions.
License: MIT License
The function arguments ...args
are an array of any (any[]). If we have a typescript function, the type is not reflected correctly.
This lib is useful, but it throws a "cancelled" error when a debounced function is called multiple times. To work with node/browser promises, I would then need to "catch" this cancelled error..but in reality it should only throw if the promise returned by the debounced function throws.
debounce(() => {
return new Promise((resolve, reject) => {
// some logic here...
resolve(); // should never throw an error
// some more logic
reject('Error message'); // this should throw
});
});
The actual function is exported to exports.default.
What this means is that when trying to "require" debounce, one has to either do
const {default: debounce} = require("debounce-async")
or
const debounce = require("debounce-async").default
When configuring this library to use a leading edge debounce, things don't work consistently.
On each consecutive call the debounce is applied in an alternating leading, then trailing, then leading fashion.
That seems to be because invokeAtLeading
never clears the latestResolve
variable upon resolution:
Lines 40 to 43 in 9d509d0
On every other call this condition is failing because latestResolve
is still set:
Line 22 in 9d509d0
And the execution falls through to invokeAtTrailing
even when latestResolve
has long since been resolved.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.