Skip to main content

event broker based on javascript generator etiher synchronous and asynchronous

This package works with Bun, Node.js, BrowsersIt is unknown whether this package works with Cloudflare Workers, Deno
JSR Score
100%
Published
3 weeks ago (1.1.0)
class EventBroker

EventBroker class that implements EventSubmitter interface.

Type Parameters

ListenEvent extends BaseEvent

The type of the event to listen for.

ReplyEvent extends BaseEvent = ListenEvent

The type of the event to reply with.

Properties

abstract
private
_listener: Generator<ReplyEvent | undefined, any, ListenEvent>
private
abstract
_startId: StartID
readonly
isStarted: boolean

Checks if the event broker is currently started.

Methods

send(event: ListenEvent): IteratorResult<ReplyEvent | undefined, any>

Sends an event and returns an iterator result.

Sends an event and waits for a reply.

start(handler: (event: ListenEvent) => ReplyEvent | void): StartID | undefined

Starts listening for events.

stop(startId: StartID, value?: unknown): IteratorResult<ReplyEvent | undefined, any> | undefined

Stops listening for events.

Add Package

deno add @soulsoftware/event-broker

Import symbol

import { EventBroker } from "@soulsoftware/event-broker";

Add Package

npx jsr add @soulsoftware/event-broker

Import symbol

import { EventBroker } from "@soulsoftware/event-broker";

Add Package

yarn dlx jsr add @soulsoftware/event-broker

Import symbol

import { EventBroker } from "@soulsoftware/event-broker";

Add Package

pnpm dlx jsr add @soulsoftware/event-broker

Import symbol

import { EventBroker } from "@soulsoftware/event-broker";

Add Package

bunx jsr add @soulsoftware/event-broker

Import symbol

import { EventBroker } from "@soulsoftware/event-broker";