# Bus

`class` in `core` · v0.1.4

<https://docs.seedcord.org/packages/core/0.1.4/classes/bus>

Registers and dispatches subscribers. Subscribers run on a programmatic or framework publish. Accessed via `core.bus`. Do not construct it directly.

```ts
class Bus extends TypedEventEmitter<SubscriptionTuples>
```

## Constructors

### constructor

```ts
Bus(core: CoreBase)
```

Constructs a new instance of the `Bus` class

## Properties

### core

```ts
protected core: CoreBase
```

## Methods

### onListenerError

```ts
protected onListenerError(
    error: unknown,
    event: string | symbol
): void
```

### publish

```ts
public publish<KeyOfSubscribers>(
    event: KeyOfSubscribers,
    data: AllSubscriptions[KeyOfSubscribers]
): boolean
```

Publishes an event to its subscribers and native listeners.

Fire-and-forget. Subscriber handlers run asynchronously and this returns before they finish. A caller cannot assume a side effect has completed. Errors thrown by a subscriber or by an `on()` listener are caught and logged, never surfaced here. One throwing listener does not stop the others. Subscribers on one key run concurrently and carry no ordering guarantee. A `'once'` subscriber is marked as executed when it starts, even if it throws. It never runs twice.

The framework's own keys are excluded. Subscribe to those and listen with `on`. The framework is their only publisher.
