# Bus

`class` in `gateway` · v0.1.0-next.3

<https://docs.seedcord.org/packages/gateway/0.1.0-next.3/classes/bus>

Registers and dispatches subscribers. Subscribers load from the configured directories and run on a programmatic or framework-event publish. Accessed via `core.bus`. Do not construct it directly.

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

## Constructors

### constructor

```ts
Bus(core: Core)
```

Constructs a new instance of the `Bus` class

## Properties

### core

```ts
protected core: Core
```

### logger

```ts
public readonly logger: Logger
```

### pluggable

```ts
protected pluggable: Core
```

## Methods

### init

```ts
abstract async init(): Promise<void>
```

### onHmr

```ts
async onHmr(_event: HmrUpdateEvent): Promise<void>
```

Reloads plugin state on an HMR update. The base implementation is a no-op, override it in your plugin.

### publish

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

Publishes an event to its subscribers and native listeners.

Fire-and-forget, so subscriber handlers run asynchronously and this returns before they complete, and callers must not assume side effects have landed. Errors thrown by a subscriber are caught and logged, never surfaced here. A `'once'` subscriber is marked as executed when it starts (even if it throws), so it never runs twice.

### registerCriticalFiles

```ts
protected registerCriticalFiles(
    patterns: string[]
): void
```

Registers critical file patterns that should trigger a full restart when changed in Dev HMR.
