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

khipu

v1.0.0

Published

A job queue

Downloads

7

Readme

Kipu

Kipu is an event queue, created to ease the sequencing of events in the web browser.

It has a couple of extra features too, most notably auto-discarding and auto-truncating.

Its designed with performance in mind. After an event has been processed, its removal from the queue is a O(1) operation. This enables consistent performance across web browsers.

Usage

This is how you create, add events and process a new Kipu:

kipu = Kipu.new()

kipu.add(myFunction)
kipu.add(anotherFunction, { context: this, options: [arg1, arg2] })

kipu.processQueue()

That's 90% of Kipu right there. Each function will be processed synchronously and wrapped in a promise that contains:

  • The results of all operations in a list until you clear the queue
  • An optional context to bind the function to
  • An options array passed as an argument to the function

That sounds cool and all, but why should I use this?

Even if the events are processed synchronously, user interactions, AJAX requests and other events are async.

You end up disabling the UI controls while waiting for a request to be finished. Or adding flag variables to signal when the next action can take place. This gets messy quickly.

Wouldn't it be cool if your event queue could handle this for you? Enter truncating and discarding.

Truncating

Let's create a queue that removes all the events but the first one from the queue after an event is processed:

kipu = Kipu.new()

kipu.add(firstFunc)

kipu.process(kipu.truncate)

kipu.add(secondFunc)
kipu.add(thirdFunc)
kipu.add(fourthFunc)

// firstFunct finished!

kipu.list() // [secondFunc]

Discarding

Discarding works in a similar fashion as truncating: it discards all but the last event in the queue after an event is processed.

kipu = Kipu.new()

kipu.add(firstFunc)

kipu.process(kipu.discard)

kipu.add(secondFunc)
kipu.add(thirdFunc)
kipu.add(fourthFunc)

// firstFunct finished!

kipu.list() // [fourthFunc]

API

new()

add(function, [context, options])

list()

clear()

isEmpty()

peek([index])

results()

process([function])

processQueue([function])

listen([function])

truncate()

discard()