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

eventure

v0.5.0

Published

<h1 align="center">Eventure</h1>

Readme

安装

npx nypm add eventure

基础用法

import { Eventure } from 'eventure'

interface Events {
	message: [text: string]
	sum: (a: number, b: number) => number
}

const events = new Eventure<Events>()

const unsubscribe = events.on('message', (text) => {
	console.log(text)
})

events.emit('message', 'hello')
unsubscribe()

events.on('sum', (a, b) => a + b)
const results = await events.emitAll('sum', 1, 2)

无返回值事件用 tuple 写;关心 listener 返回值时,用函数签名写。完整方法说明见 API.md

功能与示例

测试文件同时作为可运行示例:

  • 调用方控制中断:fire / fireAsync 逐个产出 listener 的 success / error / async 结果;调用方可以 break / return,后续 listener 不会继续执行。
  • 监听方控制短路:waterfall 让 listener 通过 next 串联;某个 listener 不调用 next 时流水线停止,并返回 { ok: false, value }
  • 单事件通道:EvtChannel 适合只管理一个事件的场景,方法与 Eventure 基本一致但不需要事件名。
  • 条件、限次与位置监听:once / manywhenat scope 支持一次性、限次、带 predicate 和指定插入位置的监听。
  • 等待下一次事件:waitFor 支持过滤、超时、取消和 AbortSignal
  • 批量收集结果:emitAll / emitSettled 分别对应快速失败和 settled 结果收集。
  • 基础行为:Eventure 基础测试 覆盖注册、触发、退订和异步错误处理。

性能

Benchmark 源码见 tinybench/onlyEmit.ts,设计说明见 PERFORMANCE.md

每个 sample 内部执行 100_000 次 emit,尽量摊薄 benchmark 自身的调度开销。主要性能收益来自 Copy-On-Write 的监听器数组设计,具体见设计说明。

bench:compare 用于和 EventEmitter3、EventEmitter2、mitt 做 emit 参考线对比;bench:api 用于 Eventure 自身 API 的 base/PR 性能回归检测。

本地记录:Bun 1.3.4,Linux x64,11th Gen Intel(R) Core(TM) i5-11400H @ 2.70GHz,hrtimeNow。参考库:EventEmitter3 ^5.0.4,EventEmitter2 ^6.4.9,mitt ^3.0.1。

Sync emit loop:

| Rank | Task | ×10^5 emits/s | RME | Samples | ns/emit | | ---: | ------------- | ------------: | ----- | ------: | ------: | | 1 | Eventure | 884.70 | 0.37% | 881 | 11.30 | | 2 | EventEmitter2 | 526.94 | 0.70% | 523 | 18.98 | | 3 | EventEmitter3 | 485.29 | 0.67% | 480 | 20.61 | | 4 | mitt | 267.76 | 0.70% | 267 | 37.35 |

Async end-to-end:

| Rank | Task | ×10^5 emits/s | RME | Samples | ns/emit | | ---: | ------------- | ------------: | ----- | ------: | ------: | | 1 | Eventure | 44.79 | 3.17% | 88 | 223.27 | | 2 | EventEmitter3 | 42.53 | 2.91% | 84 | 235.13 | | 3 | EventEmitter2 | 40.03 | 3.20% | 79 | 249.83 | | 4 | mitt | 31.53 | 3.16% | 63 | 317.15 |