npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@zuze/d-queue

v2.0.0

Published

A ridiculously small and simple debounce queue

Downloads

3

Readme

d-queue

npm version Coverage Status Build Status

A DebounceQueue debounces functions to run only when a queue is idle.

Create a DebounceQueue:

import dq from '@zuze/d-queue';
...
const { run, queue, dequeue } = dq(argumentProcessor);

Add a function to be run when the queue is idle:

queue(fnToBeRun,arguments)

If the queue is not busy, this function will be run immediately. To make a queue busy, call run with a synchronous or asynchronous function. No functions added to the queue while it is busy will be called. After the queue becomes idle, all existing queued functions will be flushed.

Why?

A DebounceQueue is highly useful for subscription-style callbacks that you do not want to get called while other things are happening.

What's an argument processor?

In the case of subscriptions, the same function reference is typically added to a DebounceQueue between flushes. An argument processor is a function that accepts the current arguments the queued function should be flushed with and the last arguments the function was flushed with and returns an array of new arguments. The default argument processor is the identity function

Example

const { run,  queue } = dq();
something.subscribe(() => run(async () => await doSomethingElse()))
const debounceSubscriptionManager = fn => somethingElse.subscribe((...args) => queue(fn,args))

The purpose of this is to allow subscriptions to be added to somethingElse that will not get called if doSomethingElse is running.

When something calls a callback, it will call the asynchronous function doSomethingElse. Any existing or new subscriptions to somethingElse will not be run until doSomethingElse has completed.

API

const { queue, dequeue, run } = dq(argumentProcessor: (nextArgs = [], lastArgs = []) => any[])

Creates a new debounce queue. Returns queue, dequeue, and run functions.

  • queue (fn: Function, args?: any[]) Accepts a function reference and (optionally) an array arguments that function should be called with. The function is run when the queue becomes idle.

  • dequeue (fn: Function) Removes a function reference from the queue.

  • run( done? => void | Promise ) Starts a process running. Any functions added to the queue will the process is running will not be run until the process is complete. It can be made async by either returning a promise or calling the done function passed to the callback as an argument.

Returning a promise and accepting a done parameter are mutually exclusive. If the callback function accepts a done parameter, it must be called.