https://github.com/cenfun/async-tick
async-tick
https://github.com/cenfun/async-tick
async debounce microtask throttle tick
Last synced: about 1 year ago
JSON representation
async-tick
- Host: GitHub
- URL: https://github.com/cenfun/async-tick
- Owner: cenfun
- License: mit
- Created: 2023-03-29T15:03:00.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-07T06:09:53.000Z (about 3 years ago)
- Last Synced: 2025-02-04T09:18:21.536Z (about 1 year ago)
- Topics: async, debounce, microtask, throttle, tick
- Language: JavaScript
- Homepage: https://cenfun.github.io/async-tick/
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# async-tick
## Preview
[https://cenfun.github.io/async-tick/](https://cenfun.github.io/async-tick/)
## Install
```
npm i async-tick
```
## microtask
```js
import { microtask } from "async-tick";
const microtaskCallback = microtask((arg) => {
console.log(arg);
});
microtaskCallback(1);
```
### microtask VS nextTick
- microtask can be canceled
```js
microtaskCallback(1);
microtaskCallback.cancel();
// will not output 1
```
- microtask no repeated calls, only using the most recent callback in an event loop
```js
microtaskCallback(1);
microtaskCallback(2);
// will only output 2
```
## throttle
```js
import { throttle } from "async-tick";
const throttleCallback = throttle((arg) => {
console.log(arg);
}, 100);
throttleCallback(1);
```
## debounce
```js
import { debounce } from "async-tick";
const debounceCallback = debounce((arg) => {
console.log(arg);
}, 100);
debounceCallback(1);
```