[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/script-host](https://jsprismarine.dev/api/@jsprismarine/script-host/index.md) / [debugger/thread](https://jsprismarine.dev/api/@jsprismarine/script-host/debugger/thread/index.md) / DebuggerThread

# Class: DebuggerThread

Defined in: [script-host/src/debugger/thread.ts:72](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/debugger/thread.ts#L72)

The debugger's socket thread. It holds at most one listener and one connection: a new `listen`
or `connect` closes both first, as Bedrock Dedicated Server's commands replace the debugger
they find. The thread starts with the first request and does not keep the process alive.

## Constructors

### Constructor

> **new DebuggerThread**(`events`): `DebuggerThread`

Defined in: [script-host/src/debugger/thread.ts:78](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/debugger/thread.ts#L78)

#### Parameters

##### events

[`DebuggerThreadEvents`](https://jsprismarine.dev/api/@jsprismarine/script-host/debugger/thread/index.md#debuggerthreadevents)

#### Returns

`DebuggerThread`

## Methods

### close()

> **close**(): `Promise`\<`void`\>

Defined in: [script-host/src/debugger/thread.ts:102](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/debugger/thread.ts#L102)

Closes the listener and the connection; the channel's end on this thread then reads as closed.

#### Returns

`Promise`\<`void`\>

***

### connect()

> **connect**(`options`): `Promise`\<`void`\>

Defined in: [script-host/src/debugger/thread.ts:97](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/debugger/thread.ts#L97)

Connects to an extension that listens, as `/script debugger connect` does. The
[DebuggerThreadEvents.connected](https://jsprismarine.dev/api/@jsprismarine/script-host/debugger/thread/index.md#connected) event comes before this resolves.

#### Parameters

##### options

[`ConnectOptions`](https://jsprismarine.dev/api/@jsprismarine/script-host/debugger/transport/index.md#connectoptions)

#### Returns

`Promise`\<`void`\>

#### Throws

When the connection fails.

***

### listen()

> **listen**(`options`): `Promise`\<`number`\>

Defined in: [script-host/src/debugger/thread.ts:88](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/debugger/thread.ts#L88)

Listens for the extension, as `/script debugger listen` does.

#### Parameters

##### options

[`ListenOptions`](https://jsprismarine.dev/api/@jsprismarine/script-host/debugger/transport/index.md#listenoptions)

#### Returns

`Promise`\<`number`\>

The port it listens on, which tells the port when 0 asked for any.

#### Throws

With Bedrock Dedicated Server's message for an address other
  than loopback without a passcode, or why the port could not be opened.

***

### terminate()

> **terminate**(): `Promise`\<`void`\>

Defined in: [script-host/src/debugger/thread.ts:108](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/debugger/thread.ts#L108)

Stops the thread, closing whatever it held.

#### Returns

`Promise`\<`void`\>
