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 🙏

© 2023 – Pkg Stats / Ryan Hefner

@antv/async-hook

v2.2.9

Published

the control flow for l7

Downloads

154,610

Readme

async-hook

L7 数据流管理工具

Usage

const asyncHook = require('async-hook');

hooks

async-hook 提供了一系列的 hook 方法用于控制方法的调用

SyncHook

SyncHook 支持对一组方法的顺序调用,同时 call 方法传入的参数会传递个方法组的每个方法使用

const hook = new SyncHook();
const funcList = [
    (args) => {
        console.log(`step1 - ${args}`);
    },
    (args) =>{
        console.log(`step2 - ${args}`);
    },
    (args) =>{
        console.log(`step3 - ${args}`);
    },
];
hook.tap('test', funcList);
hook.call('call');
// step1 - call, step2 - call, step3 - call

SyncBailHook

使用方法类似 SyncHook,但是不支持 call 传值

SyncWaterfallHook

SyncWaterfallHook 支持对一组方法的顺序调用,正常情况下方法组会在执行 call 方法之后全部执行,但可以通过每个函数的返回值控制提前结束

const hook = new SyncHook();
const funcList = [
    () => { // 执行第一个函数
        console.log('step1');
        return true;
    },
    () =>{ // 上一个函数返回值为 true,继续往下执行
        // do something
        console.log('step2');
        return false
    },
    () =>{ // 上一个函数返回值为 false(void、null、undefined、0),不再往下执行
        // do something
        console.log('step3');
        return true
    },
];
hook.tap('test', funcList);
hook.call('call');
// step1, step2

AsyncSeriesHook

使用类似 SyncHook,不过方法组中都是异步方法

AsyncSeriesBailHook

使用类似 AsyncSeriesHook,但是不支持 call 传值

AsyncWaterfallHook

AsyncWaterfallHook 支持对一组异步方法的顺序调用,正常情况下方法组会在执行 call 方法之后全部执行,但可以通过每个函数的返回值控制提前结束

const hook = new AsyncWaterfallHook();
const funcList = [
    () => { // 执行第一个函数
        console.log('step1');
        return new Promise((resolve) => setTimeout(() => resolve(true), 100))
    },
    async () =>{ // 上一个函数返回值为 true,继续往下执行
        // do something
        console.log('step2');
        return true
    },
    async () =>{ // 上一个函数返回值为 true,继续往下执行
        // do something
        console.log('step3');
        return false
    },
    async () =>{ // 上一个函数返回值为 false(void、null、undefined、0),不再往下执行
        // do something
        console.log('step4');
        return true
    },
];
hook.tapPromise('test', funcList);
hook.promise();
// step1, step2, step3

AsyncParallelHook

控制一组异步方法的并行调用,类似 Promise.all