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

@skapoor8/teak

v1.0.3

Published

An async task queue

Downloads

1

Readme

Teak.js

A simple async task queue. Preserve order of async tasks.

Usage

To install:

npm i @skapoor8/teak

Use in node.js:

const TaskQueue = require('@skapoor8/teak');

function main() {
    var tq = new TaskQueue();

    var wait = (ms) => new Promise((resolve, reject) => {setTimeout(() => resolve(ms), ms)});

    console.log('Start time:', new Date());
    tq.enqueue(wait, [1000]).then((res) => console.log(`${res} seconds passed. Current time:`, new Date()));
    tq.enqueue(wait, [5000]).then((res) => console.log(`${res} seconds passed. Current time:`, new Date()));
    tq.enqueue(wait, [10000]).then((res) => {
        console.log(`${res} seconds passed. Current time:`, new Date());
        tq.enqueue(wait, [1000]).then(res => console.log(`${res} seconds passed. Current time:`, new Date()));  
    });
}
main();

Output in console:

Start time: 2021-07-03T21:04:53.536Z
1000 seconds passed. Current time: 2021-07-03T21:04:54.548Z
5000 seconds passed. Current time: 2021-07-03T21:04:59.551Z
10000 seconds passed. Current time: 2021-07-03T21:05:09.552Z
1000 seconds passed. Current time: 2021-07-03T21:05:10.556Z

Use-Cases

Typically async tasks like the one show above can be performed in order by simply using async-await. This is a little trickier on the server side when tasks may be enqueued in response to a http request, and therefore we cannot use the await keyword or chain callbacks to ensure tasks are performed in order. Teak.js can be used in such situations.

Examples:

  1. Synchronizing writes to a file in response to requests
  2. Unique id generation

API

  1. new TaskQueue()

    • returns a task queue
  2. TaskQueue.enqueue(f, args)

    • returns a Promise that is resolved when f is called and resolved
    • f is an async function
    • args is an array of arguments expected by f

Possible Improvements

  1. Needs thorough testing, especially in browser environment
  2. Needs ES6 wrapper
  3. Is error handling idiomatic?
  4. Can interface be better?
  5. What happens when an enqueued function throws an error?