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

queue-local

v0.1.2

Published

# 一个简单基于内存的并发控制队列

Readme

local-queue

一个简单基于内存的并发控制队列

Installation

yarn add queue-local

or

npm install -save queue-local

Example

import { Queue, QueueOptions } from "../src";

const p1 = () => {
    return new Promise((resolve => {
        setTimeout(() => {
            return resolve(1)
        }, 600)
    }))
}

const p2 = () => {
    return new Promise((_, reject) => {
        setTimeout(() => {
            return reject("error 2")
        }, 600)
    })
}


const p3 = (time: number, msg: string) => {
    return new Promise((resolve => {
        setTimeout(() => {
            return resolve(msg)
        }, time)
    }))
}

const p4 = (time: number) => {
    return new Promise((_, reject) => {
        setTimeout(() => {
            return reject("error 4")
        }, time)
    })
}

class MyQueue extends Queue {
    constructor(options: QueueOptions, logger: any) {
        super(options);
        this.logInfo = (msg => logger.info(msg))
        this.onError = (err, msg) => {
            logger.error(err, msg)
        }
    }
}

const q = new Queue({
    max: 2,   // 同时最大可执行数量
    retryTimes: 3,  //执行单元出错重试次数
    retryType: 0  //重试模式 0:搁置执行(插入队列尾部重试),1:优先执行 (插入队列头部重试)
})
q.push({
    fn: p1,
    args: [],
    onSuccess: (res) => {
        console.log(`p1 方法完成了:结果:${res}`)
    }
})
q.push({
    fn: p2,
    args: [],
    tryTimes: 5,
    onError: (err) => {
        console.log(`p2 方法失败了:结果:${err}`)
    }
})
q.push({
    fn: p3,
    args: [600, 'test 3'],
    onSuccess: (res) => {
        console.log(`p3 方法完成了:结果:${res}`)
    }
})
q.jump({ fn: p4, args: [500] })

Method

export
interface
QueueDto
{
    fn: (args: any) => Promise < any >;
    args: any[];
    onSuccess ? : (res: any) => any;
    onError ? : (res: any) => any;
    tryTimes ? : number;
}

| 方法 | 描述 | 参数 | | --------- | ----------------------------------------------- | ------ | | push | 向队列尾部添加任务 | QueueDto | | unshift |向队列头部添加任务 | QueueDto | | go | 向队列尾部添加任务,并立刻开始任务 | QueueDto | | jump | 向队列头部添加任务,并立刻开始任务 | QueueDto | | start | 队列开始执行 | / | | stop | 队列暂停 | / | | setMax | 设置最大执行数量 | number | | getMax | 获取最大执行数量| / | | getRetryTimes | 获取重试次数 | / | | setRetryTimes | 设置重试次数| number | | getRetryType | 获取重试方式 | / | | changeRetryType | 改变重试方式| / |