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

schlange

v5.0.1

Published

A lightweight and flexible queue management library written in TypeScript. It provides a simple way to create and manage queues, with built-in error recovery and support for custom recovery strategies. Event-driven with event subscriptions.

Downloads

5

Readme

schlange 🐍

A lightweight and flexible queue management library written in TypeScript. It provides a simple way to create and manage queues, with built-in error recovery and support for custom recovery strategies. Event-driven with event subscriptions.

Installation

Yarn

yarn add schlange

NPM

npm install schlange --save

Example

// Define a processing function for the queue
async function processData(item) {
  console.log(`Processing: ${item.data}`)
  // Simulate processing time
  await new Promise((resolve) => setTimeout(resolve, 1000))
}

// Configure the queue
const queueProps: QueueProps<string> = {
  processFunction: processData,
  idGenerator: () =>
    Math.random()
      .toString(36)
      .substr(2, 9),
}

// Create the queue
const queue = createQueue(queueProps)

// Subscribe to events
queue.onItemAdded((item) => console.log(`Item added: ${item.data}`))
queue.onItemCompleted((id) => console.log(`Item completed: ${id}`))
queue.onProcessingCompleted(() => console.log(`All done!`))

// Add items to the queue
queue.addItem('Item 1')
queue.addItem('Item 2')

API

createQueue(props: QueueProps): Queue

The createQueue function takes a QueueProps object and returns a new Queue instance.

QueueProps properties:

  • processFunction: A function that will process the queue items. It should return a Promise.
  • idGenerator: A function that generates unique IDs for queue items.
  • recoveryStrategy (optional): A custom recovery strategy. By default, the library uses the defaultRecoveryStrategy.

Queue

The Queue instance provides the following methods and properties:

  • items: An array of QueueItem<T> objects.
  • isProcessing: A boolean that indicates if the queue is currently being processed.

Event subscription methods:

  • onItemAdded(callback: (item: QueueItem<T>) => void)
  • onItemRemoved(callback: (id: string) => void)
  • onItemsChange: (callback: (items: QueueItem<T>[]) => void) => void
  • onItemsCleared(callback: () => void)
  • onItemUpdated(callback: (args: { id: string; updatedItem: Partial<QueueItem<T>> }) => void)
  • onProcessingChange(callback: () => void)
  • onItemCompleted(callback: (id: string) => void)
  • onItemError(callback: (args: { id: string; error: Error }) => void)
  • onProcessingCompleted(callback: () => void)

Queue manipulation methods:

  • addItem(data: T): Add an item to the queue.
  • removeItem(id: string): Remove an item from the queue by its ID.
  • updateItem(id: string, updatedItem: Partial<QueueItem<T>>): Update an item in the queue.
  • startProcessing(): Start processing the queue.
  • stopProcessing(): Stop processing the queue.
  • clearItems(): Clear the entire queue.
  • dispose(): Dispose the queue instance and clean up resources.

Notice

This library is open source software released under the MIT license. See the LICENSE file for more information. This code is provided as-is, without any warranty or guarantee of any kind. Use at your own risk. I cannot be held responsible for any issues or damages that may arise from the use of this code. However, I have done my best to ensure that it is well-written and thoroughly tested, and I am always open to feedback and suggestions for improvement. Thank you for your understanding. I hope you enjoy using it and find it useful in your projects. If you have any questions or feedback, please don't hesitate to reach out.