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

@bazariodev/fsm-effects

v0.1.0

Published

Effects runner for @bazariodev/fsm — state-entry effects with cancellation, cleanup, and re-entrant send support for realtime communication workflows.

Readme

@bazariodev/fsm-effects

Effects runner for @bazariodev/fsm. Runs declarative state-entry effects with AbortSignal cancellation, sync or async bodies, optional cleanup callbacks, and a guarded send for driving the machine from inside an effect.

Full design rationale: Effects.md ADR.

Install

pnpm add @bazariodev/fsm-effects @bazariodev/fsm

@bazariodev/fsm is a peer dependency.

Usage

import { FsmEffects } from '@bazariodev/fsm-effects';

const effects = new FsmEffects(callMachine, {
  effects: {
    // sync body + cleanup: cleanup runs when the state is left
    ringing: () => {
      const tone = startRingback();
      return () => tone.stop();
    },
    // async body: abort the work when the state is left via `signal`
    dialing: async (snapshot, { signal, send }) => {
      const res = await fetch('/invite', { signal });
      send(res.ok ? { type: 'ANSWERED' } : { type: 'FAILED' });
    },
    // interval driven by `send`; cleanup clears it on leave
    connected: (snapshot, { send }) => {
      const id = setInterval(() => send({ type: 'PING' }), 5_000);
      return () => clearInterval(id);
    },
    // wildcard runs on every entry, after the state-specific effects
    '*': (snapshot) => log(snapshot.value),
  },
});

effects.stop(); // or `using effects = new FsmEffects(...)`

An effect gets the committed snapshot and { signal, send }. Return nothing, a cleanup function, or a promise of either. Multiple effects per state run in declaration order; state-specific effects run before *.

Design decisions

  • Composition, not core. The runner is a subscribe consumer — it never touches machine internals. The base core stays synchronous and effect-free, and effect bugs can't corrupt machine state.
  • State-entry only (v1). Effects attach to states, not transitions. Need transition awareness? Read snapshot.previousValue inside the effect.
  • Cancellation. One AbortController per active state. Leaving the state (or stop()) aborts its signal. A returned sync cleanup runs on abort; an async cleanup runs when its promise settles, even if abort already fired.
  • Guarded send. api.send no-ops once the signal is aborted, so effects needn't guard every call site. Machine errors raised by send surface at the effect's call site; if uncaught they're contained like any effect throw (logged, runner survives). No error event is auto-sent.

Re-entrancy: the drain loop

A send() from inside an effect or a cleanup runs synchronously, so it can re-enter the runner before the current transition's work is done. The runner serializes all of it through a single drain loop: a nested send() only records the latest target and returns; the active loop owns every controller swap and spawn. This guarantees:

  • all leaving-state cleanups finish before any entered-state effect runs — they never interleave;
  • pass-through states are skipped — in a synchronous A → B → C cascade only the resting state's (C) effects spawn;
  • stale callbacks are dropped via a monotonic version guard.

Self-transitions (A → A) don't restart effects. They're detected by comparing the incoming snapshot's value against #processedState, a notification tracker updated when each non-self snapshot is observed — kept deliberately separate from the per-turn AbortController, so the provisional controller swap never influences a self-transition decision.

Error policy

  • sync throw from an effect → logged at error, contained, siblings still run;
  • async rejection → error, or debug if the signal already aborted (e.g. a wrapped fetch AbortError);
  • cleanup throw → logged, doesn't block other cleanups;
  • nothing is auto-sent — send({ type: 'EFFECT_FAILED' }) from your own catch if you want that.

stop()

Aborts the current controller (running its cleanups), unsubscribes, and ignores later transitions. Idempotent. [Symbol.dispose] aliases it for using.

License

MIT