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

push-and-wait-queue

v1.0.1

Published

Just a boilerplate for building a library with TS + Github action for testing and releasing

Downloads

6

Readme

Build Status - GitHub Actions semantic-release npm npm

PushAndWaitQueue

A simple Promise based queue, that allows you to push(enqueue) actions and wait till it gets to their turn before resolving or also wait for the entire queue to be empty before resolving.

Queue up idempotent operations that can run simultaneously and return the same value even when there's a dependency that can cause the operation to return different value. For example, you can queue up all calls to find or create an entity if not available, if available return the value. If the call is run simultaneously, we might end up with a lot of created entities. With Queue, you can add any call to the queue, so they are waiting for the first find or create operation to be done before returning the entity. see unique user id test

yarn add push-and-wait-queue
npm install push-and-wait-queue

Browser, you can use UNPKG or JSDelivr

<script src="https://cdn.jsdelivr.net/npm/push-and-wait-queue@latest/build/index.min.js"></script>

APIs

Init

const queue = new PushAndWaitQueue();

Enqueue tasks

import PushAndWaitQueue from "push-and-wait-queue";

const queue = new PushAndWaitQueue();

queue.push(task: ITask);

interface ITask<T> {
    action: ()=>Promise<T>
    onDone?: (err: Error|undefined, result?: T)=>void
}

| Task fields | Description | | ----------- | ----------------------------------------------------------------------------------- | | action | required a function that returns a Promise | | onDone | optional a function that handles either the result or error from action promise |

Usage

see tests

import PushAndWaitQueue from "push-and-wait-queue";

const queue = new PushAndWaitQueue();
const valueFromTask1;
const task1 = {
  action: async () => {
    // long running process
    // return value
    return "3000 entities";
  },
  onDone: (err, resultOfAction) => {
    valueFromTask1 = resultOfAction;
  },
};
const task2 = {
  action: async () => {
    // use value from last tasks
    return `with value is ${valueFromTask1}`;
  },
  onDone: (err, resultOfAction) => {
    console.log(resultOfAction);
  },
};
queue.push(task1).then(() => {});
queue.push(task2).then(() => {});

Wait for Queue to be Idle or completed

You can wait at any time for a queue to be done or idle via .push(...).then since it returns a running instance of the queue

...
const onQueueCompleted = () => {
    console.log('queue is idle/completed')
}

queue.push(...).then(onQueueCompleted)

Contributing

Clone repo and run

yarn install

Commits pattern

Every PR title or at least one commit must follow conventional commit message pattern.

Available dev scripts:

yarn start

Start the library build and test in watch mode for every file edit.

yarn build

Build distribution bundle to ./build/ directory.

yarn test

Lints and test library.

yarn lint

Uses ts-standard for linting so you don't have to worry about ESLint configurations

yarn lint:fix

Automatically fixes any lint errors encountered.

yarn build:watch

Run build script in watch mode.