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

ev-queue

v1.0.3

Published

Queue asynchronous functions, that can be executed in sequence with delay.

Downloads

4

Readme

ev-queue

Queue asynchronous functions, that can be executed in sequence with delay.

Motivation

I came across a scenario where I needed to schedule data fetching for a third-party API to update the database for historical records. I wanted to serve fresh data from the API to the users unless they are browsing through previous records, in which case the data should be served from the database. The problem with that is the cron job was specifically built to handle delays keeping in mind the delay that was needed to not exceed the rate limit. If a user were to send a request at the time cron is running, it would have messed up delays possibly making the entire task fail.

Now, there can be multiple ways to work around this scenario. And so, I created this little thing.

How does it work?

It creates two queues 1. for high-priority tasks and 2. for low-priority ones. At every cycle, it checks if the high-priority queue has any tasks if tasks are present, they are queued first to be executed.

Installation

npm install ev-queue

Usage

const EvQueue = require('ev-queue');

const options = { delay: 100 }

const queue = new EvQueue(options);

Options

  • delay - the delay between async tasks (in ms)
  • maxSize - the maximum size of the queue for low-priority tasks. Defaults to 100.
  • maxHighPriority - the maximum size of the queue for high-priority tasks. Defaults to 10.

Methods

add

Adds an async task to the queue.

queue.add(asyncTask, priority);
/** returns a promise that resolves with the result of asyncTask */
  • asyncTask: A function that returns a Promise.
  • priority: low or high. Defaults to low.

Upcoming features

  • Options to add concurrency.
  • No blocking execution of high-priority tasks.
  • Option to specify rate-limit directly.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT