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

taskset

v0.2.0

Published

async tasks runner

Downloads

11

Readme

taskset - 任务运行器集合

前言

安装

npm i taskset
# or
pnpm add taskset

toAsyncTaskResult

说明

/**
 * @desc 通过tryCatch执行异步任务,并返回其错误和结果
 * @param {function} asyncTask
 * @param {any} [...args]
 * @return {array} [error, result]
 */

示例

import { toAsyncTaskResult } from "taskset";

const [error, result] = await toAsyncTaskResult(() => fetch("/xxx-api"));

runAsyncTasksFlowWithHooks

说明

/**
 * @desc runAsyncTasksFlow 的hooks版本
 * @params {array<function>} tasks - 初始的异步任务流
 * @params {object} hookTasks
 * @params {object} [hookTasks.onError] - 任务流程报错时执行该方法; (err, ...args) => undefined
 * @params {object} [hookTasks.onFinish] - 任务流程结束时执行该方法(未发生错误时); (...args) => undefined
 * @params {object} [hookTasks.onStart] - 任务流程启动时执行该方法; (...args) => undefined
 * @params {object} [hookTasks.onEnd] - 任务流程结束时执行该方法(无论过程成功还是失败); (...args) => undefined
 * @param {array<function>} asyncTasks - 初始的异步任务列表
 * @param {function|null} isBreak - 是否要中断任务列表的执行; isBreak(...args) -> boolean
 * @param {any} [...args] - 任务入参列表
 * @return {undefined}
 */

示例

import { runAsyncTasksFlowWithHooks } from "taskset";

const refuseTask = async (req, res) => {
  res.end("");
};

const notFoundTask = async (req, res) => {
  res.end("Not Found");
};

const entryTask = async (req, res) => {
  if (req.path.startsWith("/admin/")) {
    // 通过返回一个新的任务列表进行分支选择
    return [refuseTask];
  } else {
    return [notFoundTask];
  }
};

const hookTasks = {
  onStart: async (req, res) => {
    req.rtime = Date.now();
  },
  onEnd: async (req, res) => {
    console.log(req.url, Date.now() - req.rtime);
  },
  onFinish: async (req, res) => {
    !res.headersSent && console.log("not response");
  },
  onError: console.error,
};

import http from "node:http";

const server = http.createServer((req, res) => {
  runAsyncTasksFlow(
    hookTasks,
    [entryTask],
    (req, res) => res.headersSent,
    req,
    res
  );
});

runAsyncTasksFlow

说明

/**
 * @desc 运行一个中途可插入可中断的异步任务列表
 * @param {array<function>} asyncTasks - 初始的异步任务列表
 * @param {function|null} isBreak - 是否要中断任务列表的执行; isBreak(...args) -> boolean
 * @param {any} [...args] - 任务入参列表
 * @return {undefined}
 */

示例

import { runAsyncTasksFlow } from "taskset";

const refuseTask = async (req, res) => {
  res.end("");
};

const notFoundTask = async (req, res) => {
  res.end("Not Found");
};

const entryTask = async (req, res) => {
  if (req.path.startsWith("/admin/")) {
    // 通过返回一个新的任务列表进行分支选择
    return [refuseTask];
  } else {
    return [notFoundTask];
  }
};

runAsyncTasksFlow([entryTask], (req, res) => res.headersSent, req, res);

createAsyncTaskPendingHandle

说明

/**
 * @desc 创建一个异步方法可pending的包装控制器
 * @eg const [newAsyncTask, setPending] = createAsyncTaskPendingHandle(asyncTask)
 * @param {function} - asyncTask
 * @return {array<function, function, array>} - [pendingAsyncTask, setPending, pendingList]
 */

示例

import { createAsyncTaskPendingHandle } from "taskset";

const [pendingFetch, setPending] = createAsyncTaskPendingHandle(window.fetch);
window.fetch = pendingFetch;

document.addEventListener("visibilitychange", () => {
  const visible = document.visibilityState === "visible";
  setPending(!visible);
});