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

concurrent-executor

v1.0.2

Published

A TypeScript concurrent task executor with timeout, retry, and execution control

Downloads

121

Readme

Node.js CI

license:MIT codecov

ConcurrentExecutor

A production-ready concurrent task executor that supports controlled scheduling of synchronous/asynchronous tasks with complete task state management, result collection, and failure control capabilities.

Quickstart

  • Via CDN: <script src="https://unpkg.com/concurrent-executor"></script>

  • Via npm:

    npm i concurrent-executor

Core Features

  • Concurrency Control - Limit the number of concurrent tasks with concurrency option
  • Dynamic Task Addition - Add tasks with add() and addAllWithMeta()
  • Task Metadata - Associate business data with tasks via meta field
  • Failure Strategies - Timeout and retry mechanisms with customizable failure handling
  • Execution Control - Pause/resume/stop execution with fine-grained control
  • Ordered Results - Results maintained in task addition order (by index)
  • Exception Handling - Capture both sync and async errors
  • Cross-Environment - Works in both browser and Node.js
  • Manual Start - Support for manual start() trigger when autoStart = false
  • Resource Cleanup - destroy() method for proper resource cleanup

Examples

Basic Usage

import { ConcurrentExecutor } from 'concurrent-executor';

const executor = new ConcurrentExecutor<number>({ concurrency: 2 });

// Add synchronous task
executor.add(() => 1);

// Add asynchronous task with metadata
executor.add(
  async () => {
    await new Promise(resolve => setTimeout(resolve, 100));
    return 2;
  },
  { id: 'async-task' }
);

// Handle completion
executor.onAllComplete = snapshot => {
  console.log(snapshot.results); // [1, 2]
  console.log(snapshot.successCount); // 2
};

Advanced Usage with Timeout and Retry

import { ConcurrentExecutor, DefaultFailureStrategy } from './concurrentExecutor';

const executor = new ConcurrentExecutor<string>({
  concurrency: 3,
  timeout: 5000, // 5 seconds timeout
  retry: 2, // retry failed tasks up to 2 times
  failureStrategy: new DefaultFailureStrategy(2),
  onProgress: (task, snapshot) => {
    console.log(`Task ${task.id} progress: ${task.progress * 100}%`);
  },
  onTaskComplete: (task, snapshot) => {
    console.log(`Task ${task.id} completed with status: ${task.status}`);
  }
});

// Add multiple tasks
executor.addAll([
  async () => {
    // Simulate some async work
    await new Promise(resolve => setTimeout(resolve, 1000));
    return 'result1';
  },
  () => 'sync-result',
  async () => {
    // This might fail and be retried
    if (Math.random() < 0.5) throw new Error('Random failure');
    return 'success';
  }
]);

// Start execution manually (if autoStart is false)
executor.start();

Task with Progress Reporting

const executor = new ConcurrentExecutor<number>({
  concurrency: 1,
  onProgress: (task, snapshot) => {
    console.log(`Task ${task.id} progress: ${task.progress * 100}%`);
  }
});

executor.add(async ctx => {
  // Simulate a task with progress updates
  for (let i = 0; i <= 100; i += 10) {
    ctx.reportProgress(i / 100);
    await new Promise(resolve => setTimeout(resolve, 100));
  }
  return 42;
});

Execution Control

const executor = new ConcurrentExecutor({ concurrency: 2, autoStart: false });

executor.add(async () => {
  await new Promise(resolve => setTimeout(resolve, 1000));
  return 'task1';
});

executor.add(async () => {
  await new Promise(resolve => setTimeout(resolve, 2000));
  return 'task2';
});

// Manually start execution
executor.start();

// Pause execution
setTimeout(() => executor.pause(), 500);

// Resume after a while
setTimeout(() => executor.resume(), 1500);

// Stop all execution
// setTimeout(() => executor.stop(), 3000);

API

Constructor Options

  • concurrency - Number of concurrent tasks (default: 5)
  • autoStart - Whether to start execution automatically (default: true)
  • timeout - Task timeout in milliseconds
  • retry - Number of retry attempts for failed tasks (default: 0)
  • failureStrategy - Custom failure handling strategy
  • onProgress - Callback for task progress updates
  • onTaskComplete - Callback when individual task completes
  • onAllComplete - Callback when all tasks complete

Methods

  • add(taskFn, meta?) - Add a single task and return its ID
  • addAll(taskFns) - Add multiple tasks
  • addAllWithMeta(tasks) - Add multiple tasks with metadata
  • pause() - Pause execution
  • resume() - Resume execution
  • start() - Start execution (if autoStart is false)
  • stop() - Stop all execution
  • destroy() - Destroy executor and cleanup resources
  • snapshot() - Get current execution snapshot
  • isDestroyed() - Check if executor is destroyed

Task Status

  • pending - Task waiting to be executed
  • running - Task currently executing
  • success - Task completed successfully
  • error - Task failed
  • timeout - Task timed out
  • stopped - Task was stopped
  • cancelled - Task was cancelled

License

MIT License (c) 2025-present chandq