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

@guanghechen/task

v2.1.2

Published

Atomic and resumable tasks

Readme

Atomic and resumable tasks implementation with observable status tracking. Provides two task types: AtomicTask for one-shot operations and ResumableTask for pausable/resumable operations.

Install

  • npm

    npm install --save @guanghechen/task
  • yarn

    yarn add @guanghechen/task

Usage

AtomicTask

For tasks that run to completion without pause/resume support:

import { AtomicTask, TaskStatusEnum, TaskStrategyEnum } from '@guanghechen/task'
import { Subscriber } from '@guanghechen/subscriber'

class DownloadTask extends AtomicTask {
  private readonly url: string

  constructor(url: string) {
    super('download-task', TaskStrategyEnum.ABORT_ON_ERROR)
    this.url = url
  }

  protected async run(): Promise<void> {
    // Perform the download operation
    console.log(`Downloading from ${this.url}`)
    await fetch(this.url)
    console.log('Download complete')
  }
}

const task = new DownloadTask('https://example.com/file')

// Subscribe to status changes
const subscriber = new Subscriber({
  onNext: (status) => {
    console.log('Status:', TaskStatusEnum[status])
  }
})
task.status.subscribe(subscriber)

// Start the task
await task.start()

// Or run to completion
await task.complete()

// Check for errors
if (task.errors.length > 0) {
  console.error('Task failed:', task.errors)
}

ResumableTask

For tasks that can be paused and resumed:

import { ResumableTask, TaskStatusEnum, TaskStrategyEnum } from '@guanghechen/task'

class BatchProcessTask extends ResumableTask {
  private readonly items: string[]

  constructor(items: string[]) {
    super('batch-process', TaskStrategyEnum.CONTINUE_ON_ERROR, 100) // 100ms poll interval
    this.items = items
  }

  protected *run(): IterableIterator<Promise<void>> {
    for (const item of this.items) {
      yield this.processItem(item)
    }
  }

  private async processItem(item: string): Promise<void> {
    console.log(`Processing: ${item}`)
    await new Promise(resolve => setTimeout(resolve, 500))
  }
}

const task = new BatchProcessTask(['item1', 'item2', 'item3'])

// Start the task
await task.start()

// Pause after some time
setTimeout(async () => {
  await task.pause()
  console.log('Task paused')

  // Resume later
  setTimeout(async () => {
    await task.resume()
    console.log('Task resumed')
  }, 2000)
}, 1000)

Task Status

Tasks have observable status with the following states:

| Status | Description | | :------------------: | :----------------------------------: | | PENDING | Task not started | | RUNNING | Task is running | | SUSPENDED | Task is paused (ResumableTask only) | | CANCELLED | Task was cancelled | | FAILED | Task failed with errors | | COMPLETED | Task completed successfully | | ATTEMPT_SUSPENDING | Attempting to pause | | ATTEMPT_RESUMING | Attempting to resume | | ATTEMPT_CANCELING | Attempting to cancel | | ATTEMPT_COMPLETING | Attempting to complete |

Task Strategy

| Strategy | Description | | :-----------------: | :--------------------------------------------: | | ABORT_ON_ERROR | Stop task execution when an error occurs | | CONTINUE_ON_ERROR | Continue execution despite errors |

Reference