Skip to content

cenfun/async-tick

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

async-tick

Preview

https://cenfun.github.io/async-tick/

Install

npm i async-tick

microtask

import { microtask } from "async-tick";

const microtaskCallback = microtask((arg) => {
    console.log(arg);
});

microtaskCallback(1);

microtask VS nextTick

  • microtask can be canceled
microtaskCallback(1);
microtaskCallback.cancel();
// will not output 1
  • microtask no repeated calls, only using the most recent callback in an event loop
microtaskCallback(1);
microtaskCallback(2);
// will only output 2

throttle

import { throttle } from "async-tick";

const throttleCallback = throttle((arg) => {
    console.log(arg);
}, 100);

throttleCallback(1);

debounce

import { debounce } from "async-tick";

const debounceCallback = debounce((arg) => {
    console.log(arg);
}, 100);

debounceCallback(1);