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

mission-watch

v0.0.6

Published

none

Readme

mission-watch

目的在于解决有若干异步程序互不关联,有一个事件想在这若干个异步程序完全执行完的情况下执行的需求;

形如

async_function1();
async_function2();
async_function3();

the_end();

然后我们希望

async_function1()

async_function2()

async_function1() 同时执行

等到三个异步程序全都完全执行完毕之后 the_end() 再执行

目前(0.0.4)只是一个思路,以后慢慢优化

思路大概是这样,创建一个函数,传入两个参数,第一个参数是一个由想要执行的不定时完成的异步程序构成的数组,第二个参数是异步完成之后最终执行的函数;

在函数中新建一个对象,监听一个Number类型的变量,该变量初始值为0,每当一个异步程序执行完成该变量累加1,等到变量数值大于等于数组的(长度 - 1)时则表明全部异步程序都执行过;

但是这样子的话,在每一个异步程序的回调里面必须有一个对上述的Number变量操作的动作;

描述有点绕,直接代码。

const time = function(){
    let ms = parseInt(Math.random() * 10) * 100; //整百
    return ms
}

let foo = function(name, end){
    let ms = time();

    setTimeout(() => {
        console.log(`这个输出来自${name}, 共延迟了${ms}毫秒`);
        end()
    }, ms)
}

let foo1 = function(f1){
    return foo('foo1', f1)
}

let foo2 = function(f2){
    return foo('foo2', f2)
}

let foo3 = function(f3){
    return foo('foo3', f3)
}

let mission = function(array, callback){
    if(array.constructor !== Array){
        console.error('第一个参数必须为数组,顶你个肺啊')
        return;
    }

    let len = array.length;
    let proxy = new Proxy({ progress: 0 }, {
        set(target, key, value, receiver){
            if(proxy.progress >= len - 1){
                callback();
            }
            return Reflect.set(target, key, value, receiver);
        }
    })

    array.forEach((item) => {
        item(function(){
            proxy.progress += 1;
        })
    })
}

mission([foo1, foo2, foo3], function(){
    console.log('end')
})
结果输出

这个输出来自foo1, 共延迟了700毫秒 这个输出来自foo3, 共延迟了800毫秒 这个输出来自foo2, 共延迟了900毫秒 end

说明

在这个函数中,所要执行的异步函数里面,需要留一个位置给异步函数,作为异步程序执行完毕之后的回调。

let foo = function(name, end){
    let ms = time();

    setTimeout(() => {
        console.log(`这个输出来自${name}, 共延迟了${ms}毫秒`);
        end()
    }, ms)
}

let foo1 = function(f1){
    return foo('foo1', f1)
}

此处的end就是所谓的异步结束的回调函数