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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@nick-wilde/js-task

v2.0.0

Published

对webworker进行封装,以类似C# Task(async、await多线程同步)的方式将CPU密集型任务拆分到Javascript的多线程环境执行。

Downloads

4

Readme

JSTask

利用Webworker实现的支持async/await异步等待的JS任务类,类似C# Task

安装

npm i @nick-wilde/js-task

示例

//模拟耗时方法
function fn(...args) {
    let startTime = performance.now()
    let now = performance.now();
    let offset = now - startTime;

    //模拟耗时运算
    let duration = Math.random() * 5 * 1000;//任务时长:0-5s
    while (offset < duration) {
        now = performance.now();
        offset = now - startTime;
    }
    console.info("线程执行序号:", args[0], "耗时(ms)", duration);

    //每一线程中的函数可以返回值
    return `hello thread ${args[0]}`;
}


// 将耗时方法包装成Task实例,此处创建5个Task进行测试
let count = 5;
let tasks = new Array(count);
for (let i = 0; i <= count; i++) {
    tasks[i] = new Task(fn, i);
}

//等待所有任务执行完毕示例
let results = await Task.All(tasks);
console.info(`所有任务均已执行完毕,同步多线程结果:`, results);

//等待任一任务执行结束示例
// let results = await Task.Race(tasks);
// console.info(`已存在执行完毕的任务(其他任务仍然会异步执行),该任务返回的结果:`, results);

API Doc

Task

Kind: global class
Date: 2022.08.22
Author: nick-wilde

new Task(fun, args)

利用Webworker实现的支持async/await异步等待的JS任务类,类似C# Task

| Param | Type | Description | | --- | --- | --- | | fun | function | 将作为任务在单独线程执行的函数 | | args | * | 要传入任务函数的参数 |

Task.All(tasks) ⇒ Promise

等待所有任务执行完毕再返回结果

Kind: static method of Task

| Param | Type | | --- | --- | | tasks | Array.<Task> |

Task.Race(tasks) ⇒ Promise

任一任务成功完成即返回结果

Kind: static method of Task

| Param | Type | | --- | --- | | tasks | Array.<Task> |