UNPKG
@prelude/function
Version:
latest (0.4.1)
0.4.1
0.4.0
0.3.0
0.2.0
0.1.0
0.0.3
Function module.
@prelude/function
/
src
/
throttle.ts
20 lines
(18 loc)
•
322 B
text/typescript
View Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const
throttle
= (
wait
:
number
,
f
: () =>
void
) => {
let
n =
0
const
g
= (
) => {
if
(n++ ===
0
) {
setTimeout
(
() =>
{
if
(--n >
0
) { n =
0
g
() } }, wait)
f
() } }
return
g }
export
default
throttle