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 AsyncEventBroker

An asynchronous event broker.

Type Parameters

ListenEvent extends BaseEvent

The type of event to listen for.

ReplyEvent extends BaseEvent = ListenEvent

The type of event to reply with.

Properties

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

Checks if the event broker is currently started.

Methods

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

Sends an event and returns an iterator result.

Sends an event and waits for a reply.

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

Starts listening for events.

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

Stops listening for events.

Add Package

deno add @soulsoftware/event-broker

Import symbol

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

Add Package

npx jsr add @soulsoftware/event-broker

Import symbol

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

Add Package

yarn dlx jsr add @soulsoftware/event-broker

Import symbol

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

Add Package

pnpm dlx jsr add @soulsoftware/event-broker

Import symbol

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

Add Package

bunx jsr add @soulsoftware/event-broker

Import symbol

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