@pacote/throttle
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

@pacote/throttle

version minified minified + gzip

A tiny throttler.

Installation

yarn add @pacote/throttle

Usage

import { throttle } from '@pacote/throttle'

const throttledFn = throttle(fn, 100)

throttledFn() // fn() is called immediately
throttledFn() // fn() is scheduled for execution after 100ms
throttledFn() // fn() is scheduled for execution, cancelling the previous one

throttle<T>(fn: (...args: T[]) => any, delay = 0): (...args: T[]) => void

throttle() creates a throttled version of the passed function.

By calling the throttled function repeatedly, the original function is called once immediately and then at most once for every period of time determined by the delay argument.

The delay argument is optional and defaults to 0 when not supplied.

The throttled function supplies a .cancel() method that can be used to cancel a pending invocation.

License

MIT © Luís Rodrigues.

Readme

Keywords

none

Package Sidebar

Install

npm i @pacote/throttle

Weekly Downloads

1,560

Version

2.0.2

License

MIT

Unpacked Size

12.4 kB

Total Files

13

Last publish

Collaborators

  • goblindegook