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

simple-queue-serve

v1.0.2

Published

这是一个轻量的 JavaScript/TypeScript 异步任务队列服务库(QueueService)与任务抽象(Task),用于在浏览器或 Node 环境中以可控并发、安全的状态管理来执行异步任务。

Readme

simple-queue-serve

这是一个轻量的 JavaScript/TypeScript 异步任务队列服务库(QueueService)与任务抽象(Task),用于在浏览器或 Node 环境中以可控并发、安全的状态管理来执行异步任务。

主要目的

  • 提供一个简单、可配置的任务队列(并发数、任务间隔),支持暂停/恢复、停止与中止。
  • 每个任务封装为 Task 对象,带有状态管理与生命周期钩子,方便观察与错误处理。

特性

  • 并发控制(concurrency)和执行间隔(interval)。
  • 任务排队(push / unshift)、移除与清空。
  • 轻量,仅依赖用于事件发射的 mitt

安装

You can install the package via npm:

npm install simple-queue-serve

可用脚本:

  • pnpm build - 使用 rslib 打包
  • pnpm dev - 打包并开启 watch
  • pnpm test - 运行测试(如果存在)

使用示例

构建后在发布包或项目内引用:

示例

import QueueService, { Task } from 'simple-queue-serve';

const q = new QueueService({ concurrency: 3, interval: 50 });

q.on('taskstart', (task) => console.log('开始任务', task.id));
q.on('taskend', (p) => console.log('进度', p));
q.on('taskerror', (p) => console.log('进度', p));
q.start();

q.push(() => Promise.resolve(console.log('简单函数任务')));

class ComplexTask extends Task {
    constructor() {
        super(() => {
            console.log('复杂任务开始');
        });
    }
}

q.push(new ComplexTask());

API 摘要

  • QueueService(option?)

    • option.concurrency: 并发数(默认 5)
    • option.interval: 每次调度的间隔 ms(默认 25)
    • 方法:pause(), resume(), abort(), push(fn|Task), unshift(fn|Task), remove(task), clear(), forEach(cb), on(event, handler), off(event, handler)
  • Task

    • 构造:new Task({ excutor: () => void | Promise, onDone?, onError? })
    • 方法:start()
    • 属性:id, state, excutor
  • QueueService Events

type IEvents<T extends Task> = {
    pause: undefined;
    resume: IQueueState;
    idle: undefined;
    taskdone: {
        running: number;
        pending: number;
        result?: unknown;
        task: T;
    };
    taskstart: {
        running: number;
        pending: number;
        task: T;
    };
    taskerror: {
        running: number;
        pending: number;
        err?: unknown;
        task: T;
    };
};

更多实现细节请参阅 src/index.tssrc/task.ts

贡献与许可

欢迎提交 issue 或 PR 来改进功能或修复 bug。请参见仓库中的贡献指南(如有)。