Skip to content

Instantly share code, notes, and snippets.

@CaptainLiao
Created January 10, 2018 07:01
Show Gist options
  • Save CaptainLiao/6359907cef8ba68ab4840bf6327e99af to your computer and use it in GitHub Desktop.
Save CaptainLiao/6359907cef8ba68ab4840bf6327e99af to your computer and use it in GitHub Desktop.
function timeout(ms) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
async function sleep(time) {
await timeout(time)
}
function throttle (method, context) {
clearTimeout(context.timerId);
context.timerId = setTimeout(() => {
method.call(context);
}, 200)
}
export {sleep, throttle}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment