A client-friendly run queue

Overview

client-run-queue

Downloads Size

This package provides a RunQueue implementation for scheduling and managing async or time-consuming functions such that client-side interactivity disruptions are minimized.

Usage Examples

import { CANCELED, DEFAULT_PRIORITY, RunQueue } from 'client-run-queue';

const main = async () => {
  const q = new RunQueue('my-queue');

  const doSomeWork = async () => {
    // …do some work – just sleeping for some random time to simulate work here
    await new Promise((resolve) => setTimeout(resolve, Math.random() * 1000));

    return Math.random();
  };

  // Scheduling an entry

  const entry = q.schedule(DEFAULT_PRIORITY, 'my-function', doSomeWork);

  // Checking its various statuses

  console.log('canceled', entry.wasCanceled());
  console.log('completed', entry.wasCompleted());
  console.log('started', entry.wasStarted());

  // Waiting for it to complete

  const result = await entry.promise;
  if (result.ok) {
    console.log('success', result.details);
  } else if (result.details === CANCELED) {
    console.log('canceled');
  } else {
    console.log('failure', result.details);
  }

  // Scheduling more entries using different priorities and options

  q.schedule(2, 'my-function', doSomeWork, { delayMSec: 1000 });
  q.schedule(0, 'my-function', doSomeWork, { neverCancel: true });
  q.schedule(1, 'my-function', doSomeWork);

  // Checking the queue length

  console.log('queue length', q.getQueueLength());

  // Canceling everything

  q.cancelAll();
};
main();

Configuration

With RunQueue, one can specify:

  • max parallelism
  • max work units and/or continuous work duration per loop iteration
  • priority and cancellable per entry (runnable function)

You may then:

  • check the status of entries
  • request cancellation of specific or all entries
  • wait for the promised values of entries

In addition to configuring individual RunQueues in the ways mentioned above, you may also specify:

  • a runAfterInteractions function to customize the coordinated scheduling mechanism for your environment (ex. React Native uses InteractionManager.runAfterInteractions). See setRunAfterInteractions. By default, runAfterInteractions uses a 0ms timeout.
  • Stats tracking functions for debugging and analyzing usage. See setStatsHandler.

React Native

As noted above, for React Native, it's recommended to use InteractionManager for runAfterInteractions. To do that, run code like the following, early in your programs execution:

setRunAfterInteractions((_id, func) => {
  const handle = InteractionManager.runAfterInteractions(func);

  return handle.cancel;
})

API Docs

Thanks

Thanks for checking it out. Feel free to create issues or otherwise provide feedback.

client-run-queue is maintained by the team at Passfolio.

You might also like...

Yet another concurrent priority task queue, yay!

YQueue Yet another concurrent priority task queue, yay! Install npm install yqueue Features Concurrency control Prioritized tasks Error handling for b

Apr 4, 2022

Opinionated, type-safe, zero-dependency max/min priority queue for JavaScript and TypeScript projects.

qewe qewe is an opinionated, type-safe, zero-dependency max/min priority queue for JavaScript and TypeScript projects. Installation Add qewe to your p

Jan 10, 2022

A document based messaging queue for Mongo, DocumentDB, and others

DocMQ Messaging Queue for any document-friendly architectures (DocumentDB, Mongo, Postgres + JSONB, etc). Why Choose This DocMQ is a good choice if yo

Dec 7, 2022

Bree is the best job scheduler for Node.js and JavaScript with cron, dates, ms, later, and human-friendly support.

Bree is the best job scheduler for Node.js and JavaScript with cron, dates, ms, later, and human-friendly support.

The best job scheduler for Node.js and JavaScript with cron, dates, ms, later, and human-friendly support. Works in Node v10+ and browsers, uses workers to spawn sandboxed processes, and supports async/await, retries, throttling, concurrency, and graceful shutdown. Simple, fast, and lightweight. Made for @ForwardEmail and @ladjs.

Dec 30, 2022

Run scheduled tasks

Berkala Berkala runs scheduled tasks specified in a YAML-based configuration. To get started, first download the binary for your operating system from

Aug 12, 2022

A Remix.run stack to monitor your BullMQ queues

A Remix.run stack to monitor your BullMQ queues

Remix Matador stack A bold interface that helps you monitor your BullMQ queues. Learn more about Remix Stacks. $ npx create-remix@latest --template nu

Dec 15, 2022

A simple Node.js APIBAN client for downloading banned IPs and inserting them into a redis set

apiban-redis A simple Node.js APIBAN client for downloading banned IPs and inserting them into a redis set. Installation This utility can be run as a

Apr 5, 2022

A client-friendly run queue

client-run-queue This package provides a RunQueue implementation for scheduling and managing async or time-consuming functions such that client-side i

Jul 5, 2022

Cloud Run Jobs Demos - A collection of samples to show you how and when to run a container to completion without a server

Cloud Run Jobs Demo Applications Cloud Run Jobs allows you to run a container to completion without a server. This repository contains a collection of

Dec 23, 2022

Run a command, watch the filesystem, stop the process on file change and then run the command again...

hubmon Run a command, watch the filesystem, stop the process on file change and then run the command again... Install You can install this command lin

Jul 30, 2022

Premium Queue package for handling distributed jobs and messages in NodeJS.

Premium Queue package for handling distributed jobs and messages in NodeJS.

The fastest, most reliable, Redis-based queue for Node. Carefully written for rock solid stability and atomicity. Sponsors · Features · UIs · Install

Dec 31, 2022

Kue is a priority job queue backed by redis, built for node.js.

Kue Kue is no longer maintained Please see e.g. Bull as an alternative. Thank you! Kue is a priority job queue backed by redis, built for node.js. PRO

Dec 20, 2022

A simple, fast, robust job/task queue for Node.js, backed by Redis.

A simple, fast, robust job/task queue for Node.js, backed by Redis.

A simple, fast, robust job/task queue for Node.js, backed by Redis. Simple: ~1000 LOC, and minimal dependencies. Fast: maximizes throughput by minimiz

Jan 5, 2023

Redis Simple Message Queue

Redis Simple Message Queue

Redis Simple Message Queue A lightweight message queue for Node.js that requires no dedicated queue server. Just a Redis server. tl;dr: If you run a R

Dec 27, 2022

BullMQ - Premium Message Queue for NodeJS based on Redis

BullMQ - Premium Message Queue for NodeJS based on Redis

The fastest, most reliable, Redis-based distributed queue for Node. Carefully written for rock solid stability and atomicity. Read the documentation F

Dec 30, 2022

Better Queue for NodeJS

Better Queue - Powerful flow control Super simple to use Better Queue is designed to be simple to set up but still let you do complex things. Persiste

Dec 17, 2022

A simple high-performance Redis message queue for Node.js.

RedisSMQ - Yet another simple Redis message queue A simple high-performance Redis message queue for Node.js. For more details about RedisSMQ design se

Dec 30, 2022

Redis-backed task queue engine with advanced task control and eventual consistency

idoit Redis-backed task queue engine with advanced task control and eventual consistency. Task grouping, chaining, iterators for huge ranges. Postpone

Dec 15, 2022
Owner
Passfolio
Passfolio
Cloud Run Jobs Demos - A collection of samples to show you how and when to run a container to completion without a server

Cloud Run Jobs Demo Applications Cloud Run Jobs allows you to run a container to completion without a server. This repository contains a collection of

Google Cloud Platform 34 Dec 23, 2022
Premium Queue package for handling distributed jobs and messages in NodeJS.

The fastest, most reliable, Redis-based queue for Node. Carefully written for rock solid stability and atomicity. Sponsors · Features · UIs · Install

null 13.5k Dec 31, 2022
Kue is a priority job queue backed by redis, built for node.js.

Kue Kue is no longer maintained Please see e.g. Bull as an alternative. Thank you! Kue is a priority job queue backed by redis, built for node.js. PRO

Automattic 9.4k Dec 20, 2022
A simple, fast, robust job/task queue for Node.js, backed by Redis.

A simple, fast, robust job/task queue for Node.js, backed by Redis. Simple: ~1000 LOC, and minimal dependencies. Fast: maximizes throughput by minimiz

Bee Queue 3.1k Jan 5, 2023
Redis Simple Message Queue

Redis Simple Message Queue A lightweight message queue for Node.js that requires no dedicated queue server. Just a Redis server. tl;dr: If you run a R

Patrick Liess 1.6k Dec 27, 2022
BullMQ - Premium Message Queue for NodeJS based on Redis

The fastest, most reliable, Redis-based distributed queue for Node. Carefully written for rock solid stability and atomicity. Read the documentation F

Taskforce.sh Inc. 3.1k Dec 30, 2022
Better Queue for NodeJS

Better Queue - Powerful flow control Super simple to use Better Queue is designed to be simple to set up but still let you do complex things. Persiste

Diamond 415 Dec 17, 2022
A simple high-performance Redis message queue for Node.js.

RedisSMQ - Yet another simple Redis message queue A simple high-performance Redis message queue for Node.js. For more details about RedisSMQ design se

null 501 Dec 30, 2022
Redis-backed task queue engine with advanced task control and eventual consistency

idoit Redis-backed task queue engine with advanced task control and eventual consistency. Task grouping, chaining, iterators for huge ranges. Postpone

Nodeca 65 Dec 15, 2022
A fast, robust and extensible distributed task/job queue for Node.js, powered by Redis.

Conveyor MQ A fast, robust and extensible distributed task/job queue for Node.js, powered by Redis. Introduction Conveyor MQ is a general purpose, dis

Conveyor MQ 45 Dec 15, 2022