effect-pubsub-event-bus

Build typed event buses using Effect PubSub and Stream primitives.

1|Updated Aug 24, 2026
One-click install
npx skills add https://github.com/lambdasolver2/opencode-effect-harness --skill effect-pubsub-event-bus-lambdasolver2
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: effect-pubsub-event-bus
Source: https://github.com/lambdasolver2/opencode-effect-harness/tree/main/packages/module-typescript/assets/skills/effect-pubsub-event-bus
Command: npx skills add https://github.com/lambdasolver2/opencode-effect-harness --skill effect-pubsub-event-bus-lambdasolver2

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires effect.

What problem does it solve? Callback-based event systems in TypeScript lack type safety, leak resources, and require manual subscription bookkeeping. This Skill provides patterns for building typed publish/subscribe event buses with Effect v4's PubSub and Stream modules, where subscriptions are scoped and cleaned up automatically. ## Core Features & Use Cases - Typed Event Bus Service: Define events as Schema.TaggedClass discriminated unions and expose publish/subscribe through a Context.Service with a Layer. - Scoped Subscriptions: Use Stream.fromPubSub with Effect.forkScoped so subscriber fibers are tied to the layer scope and cleaned up automatically. - Per-Type Channels & Shutdown Events: Maintain a Map of per-type PubSub channels for high-throughput systems and publish a final disposal event before shutdown. - Testing Choreography: Fork consumers, use a registration barrier, publish events, and gate assertions on a Deferred. - Use Case: A file-watcher service publishes FileChanged events; multiple downstream services subscribe with filtered streams and react without any manual unsubscribe logic. ## Quick Start Ask the AI to build a typed event bus service with Effect PubSub that publishes FileChanged events and lets subscribers consume them as scoped streams.

Frequently Asked Questions about effect-pubsub-event-bus

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I build a typed event bus with Effect PubSub?

Define events as Schema.TaggedClass classes, create a PubSub.unbounded channel inside a Layer.effect, and expose publish and subscribe through a Context.Service. Subscribers consume events via Stream.fromPubSub filtered by event class.

How to subscribe to Effect PubSub events without manual cleanup?

Use Stream.fromPubSub piped through Stream.runForEach and launched with Effect.forkScoped. The subscription fiber is tied to the enclosing scope, so it terminates automatically when the layer scope closes without explicit unsubscribe calls.

What is the difference between Effect forkScoped and forkChild?

Effect.forkScoped ties the fiber to the Scope lifecycle, while Effect.forkChild ties it to the parent fiber. For subscriptions registered during layer construction, forkScoped is correct because the subscription must live as long as the layer's scope.

Does Effect PubSub replay events to late subscribers?

PubSub delivers messages only to active subscribers by default. You can configure a replay buffer with the replay option so late subscribers receive the most recent N values, but it is bounded and not durable storage.

Why does my PubSub test hang when asserting no more events?

PubSub.takeAll suspends when the subscription is empty and returns a NonEmptyArray, so it hangs waiting for an event. Use PubSub.takeUpTo instead, which returns immediately with whatever is buffered, possibly an empty array.

When should I use bounded vs unbounded PubSub in Effect?

Use unbounded when no backpressure is needed and nothing should be dropped for attached subscribers. Use bounded for backpressure with memory limits, sliding when latest events matter most, and dropping when burst absorption takes priority.