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 🙏

© 2024 – Pkg Stats / Ryan Hefner

king-promise

v1.0.0

Published

a kind of circuit breaker

Downloads

5

Readme

king-promise

一个提供网关功能的Promise封装,或者说是一个circuit breaker,灵感来源自opossum

快速开始

详见test和类型

不得不说

我小时候和同伴打乒乓球时,有一种玩法叫“王士兵”,球桌一边是“王”,一边是“士”和“兵”,“王”发球而“士”和“兵”轮番接球,当一方没接住,则扣掉一条命直至降级,“王”为了自保必是全力出击,“士”和“兵”虽想升职却要提防彼此。当只有一张球桌,打球的人多且水平参差不齐时,最是适合

king-promise的架构就是来源于此,“士兵”负责执行任务(也就是一个返回promise的函数),不论伤亡(就算这个任务每次执行都会抛出错误,士兵依然前仆后继),“将军”负责指挥,他会管理、安排士兵去执行各个任务,并观察士兵任务的耗时,任务的失败率,并安排策略,决定是否继续执行or重启任务,“将军”会将一切情报交给“国王”,但“国王”并不能直接干预自己的下属,开发者可以从国王这里知道自己需要知道的

具体的功能就是:

  1. 熔断:当某个任务在某段时间内频繁报错(可能是下游接口出了问题),“将军”可以中断这项服务
  2. 降级:同上时,“将军”可以让“士兵”执行降级任务
  3. 限流:当某个任务某时间内执行数过多,“将军”可以暂停它
  4. 预热: 当一个任务停止后,“将军”可以安排士兵去测试这个任务,当这个任务又可以重新执行时(下游接口恢复正常),“将军”可以慢慢增加士兵去执行这个任务 ...

可惜的是,大概有十年,我再也没有在身边听过这种玩法了