2.0.0 • Published 9 months ago

easy-queuer v2.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

easy-queuer

A lightweight queuing library that also provides convenient wrappers for managing timeouts and intervals with easier removal. It offers a simple and efficient way to control the execution time of functions.

Installation

npm i easy-queuer

Usage

Two convenience functions: timer() and interval() both return a function that can be used to clear the timeout or interval, respectively.

import { timer, interval } from "easy-queuer";

// Example use in a react component
useEffect(timer(() => render(), 1000), [...deps]);
useEffect(interval(() => render(), 1000), [...deps]);

makeQueuer()

The makeQueuer() function creates a timed queue that restricts the execution frequency of the function passed to it. This is particularly useful when you want to limit the call rate of some expensive functions.

import { makeQueuer } from "easy-queuer";

const queuer = useMemo(() => makeQueuer(100), []);
// ...
useEffect(() => queuer.push(drawCanvas), [...deps]);

In the above example, makeQueuer(100) creates a queuer that no function pushed to it is called no more than 10 times per second. The queuer will always use the latest function it receives.

It's also possible to override the queuer's interval when a crucial dependency changes. By calling push() with the second argument set to true, the drawCanvas() function will be run immediately.

2.0.0

9 months ago

1.2.0

10 months ago

1.1.0

10 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.2.2

10 months ago

1.0.4

11 months ago

1.2.1

10 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago