Sudoo-Throttle

Build Status codecov npm version downloads

:mushroom: Throttle for Node

Install

yarn add @sudoo/throttle
# Or
npm install @sudoo/throttle --save

Throttle

import { Throttle } from "@sudoo/throttle";

const throttle = Throttle.create(async (...args) => {
    await doSomethingCostALot(args);
}, 1000);

for(1000 Times){
    throttle.execute(args); // Only one will be executed every 1000 ms
}

throttle.reset(); // Cancel

Debounce

import { Debounce } from "@sudoo/throttle";

const debounce = Debounce.create(async (...args) => {
    await doSomethingCostALot(args);
}, 1000);

for(1000 Times){
    debounce.execute(args); // Only the last call will be executed since all action called within 1000 ms
}

debounce.reset(); // Cancel