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

tickque

v0.1.3

Published

auto shifting queue based on denque

Downloads

12

Readme

tickque

A queue that auto shift itself based on the given interval.

  • You might not want to create timer for each incoming request.
  • The queue is designed to align those requests into time slots.
  • When each time slot is shifted, process requests in the slot in batch.

Get started

const Queue = require('tickque')

let queue = new Queue(1, 10, true)
queue.onShift(itemsIterator => { ... })

queue.add('shifted after 10 sec'))
queue.add('shifted after 2 sec'), 2)

API

Queue(interval = 1, limit = 0, preAlloc = false)

  • interval: auto shifting interval in second
  • limit: maximum ttl (queue length), which make it fixed length
  • preAlloc: alloc slots during construction if limit > 0

Note: It's possible to set interval to float point but the queue uses setInterval which cannot guarantee pricise timers. There will be ms delays (depending on CPU usage) before each onShift callback due to single thread JS model. It's roughly 1 second error every 8 minutes

onShift(cb)

  • cb will be invoked with the items iterator in the shifted time slot

add(item, ttl)

  • item: the object to be inserted into the ttl specified time slot
  • ttl: tick to live -- time slot offset (positive integer)

The queue grows automatically until limit, if ttl is larger than current queue length. This is one time O(n) operation, n equals the length of queue. When queue is contructred with preAlloc, complexity is always O(1). If ttl is omitted, item is added to the end of queue.

peek(ttl)

Returns the items in the given time slot in O(1).

remove(item)

Remove the given item in O(1).

has(item)

Check if the item is in the queue in O(1).

length

Returns the queue length in O(1).

items()

Returns iterator of all items in O(1).

count()

Returns number of all items in O(1).

start(immediate = false)

  • immediate: tick at once if true, otherwise tick after interval

Start queue shifting. Note the queue starts automatically when item is added.

stop()

Stop queue shifting. Note the queue stops automatically once it's empty.