class · Browser and Node

# Bus

An in-memory network that delivers bytes by receiver VID, and lets the UI tap every message.

`@toip-tools/trust-core` · [View source](https://github.com/yourbuddyconner/toip-tools/blob/main/packages/trust-core/src/bus.ts#L26)

Import:

```ts
import { Bus } from "@toip-tools/trust-core";
```

## Constructor

Constructor:

```ts
new (clock: Clock): Bus;
```

### Parameters

- **`clock` (required)**: `Clock`

### Returns

`Bus`

## Methods

### `attach`

Signature:

```ts
attach(vid: string, deliver: Deliver): void;
```

#### Parameters

- **`vid` (required)**: `string`
- **`deliver` (required)**: `Deliver`

#### Returns

`void`

### `detach`

Signature:

```ts
detach(vid: string): void;
```

#### Parameters

- **`vid` (required)**: `string`

#### Returns

`void`

### `setOnline`

Signature:

```ts
setOnline(vid: string, online: boolean): void;
```

#### Parameters

- **`vid` (required)**: `string`
- **`online` (required)**: `boolean`

#### Returns

`void`

### `isOnline`

Signature:

```ts
isOnline(vid: string): boolean;
```

#### Parameters

- **`vid` (required)**: `string`

#### Returns

`boolean`

### `send`

Records the message and delivers it asynchronously. An unknown or offline recipient marks it undelivered.

Signature:

```ts
send(from: string, to: string, wire: Uint8Array): WireRecord;
```

#### Parameters

- **`from` (required)**: `string`
- **`to` (required)**: `string`
- **`wire` (required)**: `Uint8Array<ArrayBufferLike>`

#### Returns

`WireRecord`

### `post`

Signature:

```ts
post(from: string, to: string, wire: Uint8Array): Promise<Delivery>;
```

#### Parameters

- **`from` (required)**: `string`
- **`to` (required)**: `string`
- **`wire` (required)**: `Uint8Array<ArrayBufferLike>`

#### Returns

`Promise<Delivery>`

### `records`

Signature:

```ts
records(): readonly WireRecord[];
```

No parameters.

#### Returns

`readonly WireRecord[]`

### `settle`

Resolves once every delivery, including the ones those deliveries cause, has finished.

Signature:

```ts
settle(): Promise<void>;
```

No parameters.

#### Returns

`Promise<void>`

### `subscribe`

Signature:

```ts
subscribe(fn: () => void): () => void;
```

#### Parameters

- **`fn` (required)**: `() => void`

#### Returns

`() => void`

### `changed`

Lets an agent tell the UI that a record it opened has changed.

Signature:

```ts
changed(): void;
```

No parameters.

#### Returns

`void`

[Usage guide](https://toip.tools/toolkit/trust-core/#usage) · [Error handling](https://toip.tools/toolkit/trust-core/#errors) · [All exports](https://toip.tools/toolkit/trust-core/api/)

---

This is the Markdown version of https://toip.tools/toolkit/trust-core/api/Bus/. An index of the documentation for AI assistants is at https://toip.tools/llms.txt.
