Skip to content

Commit

Permalink
Update time.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Matoseb committed Jul 26, 2023
1 parent fe65fe3 commit 33c8178
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ export class Clock {

export function throttle(callback, millis) {
let timeout
let wait = 0
let timestamp = -millis
let event
return (e) => {
event = e
if (timeout) return

const wait = Math.min(Math.max(timestamp + millis - Date.now(), 0), millis)

timeout = globalThis.setTimeout(() => {
callback(e)
callback(event)
timeout = undefined
timestamp = Date.now()
}, wait)
wait = millis
}
}

1 comment on commit 33c8178

@vercel
Copy link

@vercel vercel bot commented on 33c8178 Jul 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

utils – ./

utils-orcin.vercel.app
utils-matoseb.vercel.app
utils-git-main-matoseb.vercel.app

Please sign in to comment.