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

pr-task-queue

v0.4.4

Published

Use your function to execute under specified conditions.

Downloads

11

Readme

js 函数的任务队列管理。

  • 支持任意函数添加至队列。
  • 添加后由外部管理任务消费状态:消费成功-移除 消费失败-重试/移除

立即开始

安装

npm i pr-task-queue

引入

// 按需引入

// 或全量引入
import { PrTaskQueue } from 'pr-task-queue'

创建队列

const taskQueue = new PrTaskQueue(['login', 'isAdmin']) // 创建一个队列 队列中含有 是否登录 是否为管理员

设置条件

taskQueue.setCondition('login', true) // 已登录

示例

const taskQueue = new PrTaskQueue(['a', 'b', 'c'])
taskQueue.setCondition('a', false)
taskQueue.setCondition('b', false)
taskQueue.setCondition('c', false)

const task = await taskQueue.createTask({
  strict: true,
  timeout: 1200,
  describe: '测试任务',
  conditionKeys: ['a'],
  func: () => {
    return new Promise(async (res, rej) => {
      const random = Math.random() * 1000
      await new Promise((resolve) => setTimeout(() => resolve(true), 500 + random))
      if (random > 500) {
        res({ state: true })
      } else {
        rej({ state: false })
      }
    })
  }
})

task.success = (e) => {
  console.log('\x1b[38;2;0;151;255m%c%s\x1b[0m', 'color:#0097ff;', `------->Breathe: success`, e)
  taskQueue.clear([task.key])
}

task.fail = async (e) => {
  console.log('\x1b[38;2;0;151;255m%c%s\x1b[0m', 'color:#0097ff;', `------->Breathe: fail`, e)
  await new Promise((resolve) => setTimeout(() => resolve(true), 1000))
  await task.exe() // 再次执行该任务 只有启用 strict=true 时 才能再次调用 task.exe()
}

task.complete = () => {
  console.log('\x1b[38;2;0;151;255m%c%s\x1b[0m', 'color:#0097ff;', `------->Breathe: complete`)
}

setInterval(() => {
  const random = Math.random()
  taskQueue.setCondition('a', random >= 0.5)
}, 5000)

清理任务

taskQueue.clear(['taskKey']) // 清理指定任务
taskQueue.clear() // 清理所有任务

查询所有条件当前状态

  • 一般用不上 当任务没有安装预期执行可调用查看
const res = taskQueue.getConditions()

查询所有待执行任务

  • 一般用不上 当任务没有安装预期执行可调用查看
const res = taskQueue.getTasks()