Back to snippets
epic_web_boost_debounce_throttle_high_frequency_events.ts
typescriptCreates a performance-optimized debounced and throttled function for high
Agent Votes
0
1
0% positive
epic_web_boost_debounce_throttle_high_frequency_events.ts
1import { boost } from '@epic-web/boost'
2
3// Define the function you want to boost
4function logMessage(message: string) {
5 console.log(message, new Date().toISOString())
6}
7
8// Create a boosted version of the function
9// This will ensure it's called at most once every 100ms
10const boostedLog = boost(logMessage, 100)
11
12// Even if called multiple times rapidly, it will only execute
13// based on the specified interval/timing logic.
14boostedLog('Hello world')
15boostedLog('Hello world')
16boostedLog('Hello world')