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

@exogee/kew

v0.4.0-beta.1

Published

A typed task queue with a simple API

Downloads

3

Readme

@exogee/kew

A typed task queue with a simple API.


Features

  • Create one or more Queues.
  • Attach Platforms for storage and data persistence.
  • Register Actions to perform various types of tasks.

Actions

  • Simple objects with lifecycle methods.
  • Can contain reducer functions to report queue data.

Tasks

  • Individual instance of an action with its data
  • Can store serializable data that persists across app restarts.

Example Usage

  • See @exogee/kew-example

API

createTaskQueue({ plugins: TaskQueuePlugin[], handlers: TaskQueueHandler[] }): TaskQueue

Convenience method to create a new task queue with the provided plugins and handlers.


async TaskQueue.run(key: keyof TH, data?: typeof key): Promise<typeof key>

Add a new task of type key to the queue with optional data


async TaskQueue.add(key: keyof TH, data?: typeof key): Promise<string>

Add a new task of type key to the queue with optional data


async TaskQueue.start(): Promise<void>

Start the queue.


TaskQueue.stop(): void

Stop the queue.


TaskQueue.reducer(reducer: keyof TR, initialValue?: typeof reducer, filter?: TaskQueueFilterFunction): Promise<typeof reducer>

Run a named reducer over the queue

Optionally, an initialValue can be provided which will be the initial value of the accumulator. Optionally, a filter function can be provided which will only apply the reducer if the filter returns true for a task.

Returns a promise with the reduced data.


TaskQueue.plugins(...plugins: TaskQueuePlugin[]): void

Register a plugin- can also be registered in createTaskQueue


TaskQueue.handlers(...handlers: TaskQueueHandler[]): void

Register one or more task handlers- can also be registered in createTaskQueue


TaskQueue.on(filter: TaskQueueFilterFunction, callback: TaskQueueEventCallback): TaskQueueEventSubscription

Subscribe to a task queue event. Returns a subscription object with a remove() method to unsubscribe.


TaskQueue.tasks(): TaskQueueItem[]

Get a list of all tasks.


async TaskQueue.clear(): Promise<void>

Remove all tasks from the queue


Example Plugin

const AsyncStoragePlugin: QueuePlugin = {
  storage: {
    // load is called when the queue data needs to be reloaded.
    async load() {
      return await AsyncStorage.getItem("TASK_QUEUE")
        .then((tasksJSON) => callback(JSON.parse(tasksJSON)))
        .catch(() => ({}));
    },

    // sync is called with the new queue data whenever the queue is updated.
    async sync(queue: QueueStorageData) {
      await AsyncStorage.setItem("TASK_QUEUE", JSON.stringify(queue));
    },
  },
};

export default AsyncStoragePlugin;

Task Context

async setData(data: any): Promise<void>

Update the task data


Named Reducers

  • Tasks can implement any number of named reducers.
  • When TaskQueue.reduce(reducerName) is called, each queue task's reducer will be called in order where available- with the accumulated result as the first parameter, and the new task data as the second.
  • An initial value can be provided to runTaskReducer as an optional second argument.