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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-native-task-queue

v0.3.1

Published

A robust, type-safe job queue for React Native and Expo with SQLite persistence, retry logic, and background processing

Readme

react-native-task-queue

NPM Version NPM Downloads Build Status License TypeScript Expo Compatible

A robust, flexible, and type-safe job queue system for Expo and React Native apps. Designed for reliability, memory efficiency, and high developer experience.

✨ Features

  • 🎯 Storage Agnostic: switch between In-Memory, AsyncStorage, SQLite, or Custom adapters.
  • 🏗 Modular Architecture: Decoupled Registry, Processor, Executor, and Store.
  • 🏗 Strictly Type Safe: First-class TypeScript support with Generics for payloads and events.
  • Advanced Retry Logic: Exponential Backoff + randomized Jitter + Dead Letter Queue (DLQ).
  • 🚦 Granular Control: Pause/Resume specific job types (Named Queue Control).
  • 📱 Mobile Optimized: Auto-recovery from crashes, network-aware processing, and memory-efficient pagination.

🏗 Architecture Overview

react-native-task-queue follows a modular design inspired by industrial messaging systems, optimized for the mobile environment.

  • Queue Singleton: Defends against React Native "Split Brain" by sharing a transparent global instance mapper based on adapter keys across Fast Refresh lifecycles.
  • Job Registry: Manages worker registrations and job-to-worker mapping.
  • Job Processor: The central orchestrator handling concurrency, backoff windows, and scheduling loops.
  • Job Executor: Manages the lifecycle of a single job attempt (Timeout, Success, Failure).
  • Storage Adapters: A lean persistence layer. Customizing storage is as simple as implementing the Adapter interface.

🚀 Quick Start

1. Installation

yarn add react-native-task-queue uuid
npx expo install expo-sqlite # Optional: for SQLite persistence

2. Basic Setup (In-Memory)

import { Queue } from 'react-native-task-queue';

// 1. Initialize the Queue
const queue = new Queue();

// 2. Register a Worker
queue.addWorker('email-sync', async (id, payload) => {
  console.log(`Syncing email for ${payload.userEmail}`);
  // Return value is stored in the 'success' event
});

// 3. Add a Job
await queue.addJob('email-sync', { userEmail: '[email protected]' });

💾 Storage & Persistence

Choose the persistence layer that fits your app's needs.

SQLite (Recommended)

Atomic, reliable, and highly performant. Best for critical background tasks. The SQLite adapter utilizes SQL-Level Filtering (filtering maximum attempts natively via SQL rather than in-memory arrays) and bounds all write operations with withTransactionAsync to avoid lock contention under heavy concurrency.

import { Queue } from 'react-native-task-queue';
import { SQLiteAdapter } from 'react-native-task-queue/sqlite';

const adapter = new SQLiteAdapter('app-queue.db');
const queue = new Queue(adapter);

AsyncStorage

Good for lightweight, non-critical persistence.

import { AsyncStorageAdapter } from 'react-native-task-queue/async-storage';
const queue = new Queue(new AsyncStorageAdapter());

🛠 Advanced Features

1. Exponential Backoff & Jitter

Prevent overwhelming your backend during outages.

queue.addJob('sync', data, {
  attempts: 5,
  timeInterval: 2000, // Bases delay: 2s, 4s, 8s, 16s... + Jitter
});

2. Dead Letter Queue (DLQ)

Move terminally failed jobs to a DLQ for later inspection.

// If the adapter supports moveToDLQ, it happens automatically after maxAttempts
queue.on('failed', (job, error) => {
  console.error(`Job ${job.id} permanently failed:`, error);
});

3. Named Queue Control

Pause or resume execution for specific job types without stopping the whole queue.

queue.pauseJob('heavy-sync');
// Later...
queue.resumeJob('heavy-sync');

🧪 Custom Adapters

react-native-task-queue is designed to be easily extensible. All core logic (retries, backoff, TTL, concurrency) is decoupled from storage, so you only need to implement a "dumb" persistence layer.

Implementation Guides

For full, production-ready implementations of custom adapters, see our detailed guides:


🔧 API Reference

Queue<T = unknown>

Main entry point.

| Method | Description | | :--------------------------------- | :------------------------------------- | | addJob(name, payload, options) | Adds a job with custom JobOptions. | | addWorker(name, fn, options) | Registers a worker. | | pauseJob(name) / resumeJob(name) | Pauses/Resumes execution per job name. | | on(event, callback) | Strictly typed event listeners. |

JobOptions

| Property | Default | Description | | :------------- | :------- | :--------------------------------- | | priority | 0 | Higher numbers run first. | | attempts | 1 | Max attempts before moving to DLQ. | | timeInterval | 0 | Base retry delay in ms. | | ttl | 7 days | Hard expiry (ms). | | onlineOnly | false | Only run when device is connected. |


🔋 Performance & Reliability

  • Atomic Claiming: SQLite and adapters use row-level locking or exclusive transactions (withExclusiveTransactionAsync) to prevent duplicate processing.
  • Graceful Execution: Unclaimed jobs dropped due to missing workers are placed back into the queue cleanly instead of prematurely failing your attempts limits.
  • Memory Safety: Uses memory-efficient pagination even if you have 10,000 jobs in the queue.
  • Crash Recovery: Auto-resets "ghost jobs" (active jobs from a previous session) on startup.

License

MIT


Built with ❤️ by Amakiri Joseph