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

@liuyunjs/promise-chain

v1.0.2

Published

创建1个 promise 执行链,可手动暂停、继续、取消、结束、重启

Readme

promise-chain

创建1个 promise 执行链,可手动暂停、继续、取消、结束、重启

安装

npm

npm i @liuyunjs/promise-chain --S

yarn

yarn add @liuyunjs/promise-chain

Api

chain: () => Operators;

创建一个执行链, 返回一组操作符

Operators

use: (onFulfilled?: (valueOrReason: any, operators: Operators) => any, onRejected?: (valueOrReason: any, operators: Operators) => any) => number;

向执行链中添加一组任务,返回本组任务的下标;可使用 eject 取消任务

eject: (index: number) => void

从执行链中取消对应任务

run: (params?: any) => any;

启动执行链,已经被启动的执行链如果需要重启应该调用 rerun 方法

pause: (value?: any) => void;

暂停正在执行中的执行链,可传入一个参数替代目前执行链的结果

restart: (value?: any)=>void;

重新启动一个暂停中的执行链,可传入一个参数替代目前执行链的结果

stop: (value?: any) => void;

停止正在执行中的执行链,调用后 run 函数会变为 fulfilled 可传入一个参数替代执行链的结果, 就是 run 函数最终执行完成的返回值

rerun: (params?: any) => void;

重新启动执行链, 可传入一个参数替代执行 run 时传入的参数

cancel: (reason?: string) => void;

取消执行中的执行链,调用后 run 函数会变为 rejected 可传入一个字符串作为 run 函数最终失败的错误提醒

示例


import { chain } from '@liuyunjs/promise-chain';

const operators = chain();
operators.use(
  (params,operators) => {
    console.log(params);
    
    return new Promise((resolve, reject) => {
      setTimeout(() => {

          // operators.restart('restart');
          // operators.pause('pause');
          // operators.rerun('rerun');
          // operators.stop('stop');
          // operators.cancel('cancel');

          // reject(new Error('reject'));
        resolve('setTimeout');
      }, 3000);
    });
  },
  (reason,operators) => {
    console.log('err', reason);
    return Promise.reject(reason);
  },
);

operators.run('chain run').then(console.log, console.log);