
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
debounce-microtasks
Advanced tools
Debounce a function using microtasks instead of timers.
import { debounceMicrotask } from "@vicary/debounce-microtask";
const debounced = debounceMicrotask((text: string) => {
console.log("debounced", text);
});
debounced("a");
debounced("b");
debounced("c");
await Promise.resolve();
// Prints "debounced a"
Throws when the specified limit is reached before the function is run, this is a
safety measure preventing recursive debounces. You may disable it with
Infinity
.
Defaults to 1000.
import { debounceMicrotask } from "@vicary/debounce-microtask";
const debounced = debounceMicrotask(
(text: string) => {
console.log("debounced", text);
},
{ debounceLimit: 1 },
);
debounced("a");
debounced("b"); // Throws
Specifies the action to take when the debounce limit is reached.
Possible values are throw
, ignore
, and invoke
.
Defaults to throw
.
import { debounceMicrotask } from "@vicary/debounce-microtask";
const debounced = debounceMicrotask(
(text: string) => {
console.log("debounced", text);
},
{ limitAction: "throw" },
);
debounced("a");
debounced("b"); // Throws
Updates the calling arguments to the latest invocation.
Defaults to false
.
import { debounceMicrotask } from "@vicary/debounce-microtask";
const debounced = debounceMicrotask(
(text: string) => {
console.log("debounced", text);
},
{ updateArguments: true },
);
debounced("a");
debounced("b");
debounced("c");
await Promise.resolve();
// Prints "debounced c"
Returns a promisified debounce function, the promise resolves when the specified function is called.
import { debounceMicrotask } from "@vicary/debounce-microtask/promise";
const debounced = debounceMicrotask(
(text: string) => {
console.log("debounced", text);
},
{
updateArguments: true,
},
);
await Promise.all([
debounced("a"),
debounced("b"),
debounced("c"),
]);
// Only prints "debounced c"
If you find a bug or would like to suggest a new feature, please open an issue or submit a pull request on GitHub.
DebounceMicrotask is licensed under the MIT License. See the LICENSE file for more information.
If you find this project useful, please consider supporting it by donating to the author.
FAQs
Debounce a function using microtasks instead of timers.
The npm package debounce-microtasks receives a total of 2,233 weekly downloads. As such, debounce-microtasks popularity was classified as popular.
We found that debounce-microtasks demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.