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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@ion-bot/flow

v0.3.0

Published

A stream.

Downloads

2

Readme

@ion-bot/flow

@ion-bot/flow logo

GitHub Org GitHub Build status codecov CodeFactor npm (scoped) GitHub code size in bytes

@ion-bot/flow 是一个使程序流在运行过程中可以便利地通过异步函数获取传入的消息的类。

Introduction

@ion-bot/flow 是一个类库,因此你可以这样将其包含进你的项目中:

import IonFlow from '@ion-bot/flow'
// 创建 Ion 实例,传入一组 behavior(下文以 behaviors 指代,基本指一组程序流)
// 同时传进的 timeout 指在多少毫秒后强制结束一次 behavior
const ion = new IonFlow(behaviors: Array, timeout = 60000: number) 
ion.push(msg) // 传入一条消息,IonFlow 实例将自动分发给各 behaviors 处理

Behavior

Behavior 是这样的对象:

const someBehavior = {
    match(msg): boolean, // 触发条件
    id(msg): PrimitiveValue, // 消息标识
    async flow(stream: IonFlowMessageStream) // 行为主体(程序流)
}

id(msg) 是一个函数,如果你想让两个 msg 交由同一次 flow 处理,则应确保对于这两个 msg 返回同一个 value。

match(msg) 是一个函数,它接受传入的消息并判断是否要开始这个 behavior;

一旦 match(msg) 返回一个 truthy value,flow(stream) 将被调用。

flow(stream) 的参数 stream 是一个 IonFlowMessageStream 实例,它有如下方法:

注意:虽然它是一个 stream.Transform 流,但不推荐使用以下标明的 API 以外的方法!

class IonFlowMessageStream extends stream.Transform {
    get(): Promise // 获取下一条消息,用法: await stream.get() 将返回下一条消息
    end() // 结束接受消息,关闭消息流。这将用于你确定不再需要新消息时。
    timeout // 赋值将重置消息流关闭的计时器。消息流将在这时间(ms)过后关闭,之后不能再读取新消息。
    waste() // 将流转换为 flowing(“浪费”)状态,收到的消息将不会持久储存
    keep() // 将流转换为 paused(“存储”)状态,收到的消息将会储存并在队列中等待读取
}

例如,获取一条(已经收到或即将到达的)消息,你只需要:

msg = await stream.get()

这样,获取消息就像同步函数一样简洁明了。

Under the Hood

在底层,@ion-bot/flow 使用了 stream.Transform 流来传递消息。

每当调用 msgGetter() 时,都将判断流内是否有信息可读;

若有则直接返回,若没有则监听 readable 事件直到有信息可读为止。

对于每个 id(msg) 对应的消息,我们使用一个流来传递,并存储在一个 Map<symbol, Map<any, IonFlowMessageStream>>内。