# InstanceManager

**Kind**: interface | **Module**: [Apps](https://docs.interop.io/desktop/reference/javascript/apps/index.md) | **Access**: `io.apps.instances`

**Source**: https://docs.interop.io/desktop/reference/javascript/apps/instancemanager/index.html

Object that can be used for managing running app instances.

## Methods

### get

Retrieves an app instance.

```ts
(options: InstanceSelect) => Promise<ApplicationInstance | null>
```

**Parameters**

- **`options`** (`InstanceSelect`, required)
  Filter for selecting an app instance.

**Returns**: `Promise<ApplicationInstance | null>`

### getContext

Retrieves the context of an app instance.

```ts
(options: InstanceSelect) => Promise<Record<string, any>>
```

**Parameters**

- **`options`** (`InstanceSelect`, required)
  Filter for selecting an app instance.

**Returns**: `Promise<Record<string, any>>`

### getMany

Retrieves all running app instances. You can also provide an optional filter to refine the result.

```ts
(filter?: InstanceFilter) => Promise<ApplicationInstance[]>
```

**Parameters**

- **`filter`** (`InstanceFilter`, optional)
  Filter for retrieving app instances.

**Returns**: `Promise<ApplicationInstance[]>`

### getState

Retrieves the current state of an app instance.

```ts
(options: InstanceSelect) => Promise<InstanceState>
```

**Parameters**

- **`options`** (`InstanceSelect`, required)
  Filter for selecting an app instance.

**Returns**: `Promise<InstanceState>`

### onStarted

Notifies when an app instance has been started. Returns an unsubscribe function.

```ts
(handler: InstanceEventHandler<InstanceStartedEvent>) => Promise<UnsubscribeFunction>
```

**Parameters**

- **`handler`** (`InstanceEventHandler<InstanceStartedEvent>`, required)
  Callback function for handling the event. Receives as an argument an object describing the started app instance.

**Returns**: `Promise<UnsubscribeFunction>`

### onStateChanged

Notifies when the current state an app instance has been changed. Returns an unsubscribe function.

```ts
(handler: InstanceEventHandler<InstanceStateChangedEvent>) => Promise<UnsubscribeFunction>
```

**Parameters**

- **`handler`** (`InstanceEventHandler<InstanceStateChangedEvent>`, required)
  Callback function for handling the event. Receives as an argument an object describing the app instance and its new state.

**Returns**: `Promise<UnsubscribeFunction>`

### onStopped

Notifies when an app instance has been stopped. Returns an unsubscribe function.

```ts
(handler: InstanceEventHandler<InstanceStoppedEvent>) => Promise<UnsubscribeFunction>
```

**Parameters**

- **`handler`** (`InstanceEventHandler<InstanceStoppedEvent>`, required)
  Callback function for handling the event. Receives as an argument an object describing the stopped app instance and a reason (optional) for stopping the instance.

**Returns**: `Promise<UnsubscribeFunction>`

### restart

Restarts an app instance.

```ts
(options: RestartInstanceOptions) => Promise<ApplicationInstance>
```

**Parameters**

- **`options`** (`RestartInstanceOptions`, required)
  Options for restarting the instance.

**Returns**: `Promise<ApplicationInstance>`

### start

Starts a new app instance.

```ts
(options: StartAppOptions) => Promise<ApplicationInstance>
```

**Parameters**

- **`options`** (`StartAppOptions`, required)
  Options for starting the app instance.

**Returns**: `Promise<ApplicationInstance>`

### stop

Stops an app instance.

```ts
(options: StopInstanceOptions) => Promise<void>
```

**Parameters**

- **`options`** (`StopInstanceOptions`, required)
  Options for stopping the app instance.

**Returns**: `Promise<void>`

### waitForReady

Waits for an app instance to be fully initialized.

```ts
(options: InstanceSelect) => Promise<void>
```

**Parameters**

- **`options`** (`InstanceSelect`, required)
  Filter for selecting an app instance.

**Returns**: `Promise<void>`

## Related types

- [ApplicationInstance](https://docs.interop.io/desktop/reference/javascript/apps/applicationinstance/index.md)
- [InstanceEventHandler](https://docs.interop.io/desktop/reference/javascript/apps/instanceeventhandler/index.md)
- [InstanceFilter](https://docs.interop.io/desktop/reference/javascript/apps/instancefilter/index.md)
- [InstanceSelect](https://docs.interop.io/desktop/reference/javascript/apps/instanceselect/index.md)
- [InstanceStartedEvent](https://docs.interop.io/desktop/reference/javascript/apps/instancestartedevent/index.md)
- [InstanceState](https://docs.interop.io/desktop/reference/javascript/apps/instancestate/index.md)
- [InstanceStateChangedEvent](https://docs.interop.io/desktop/reference/javascript/apps/instancestatechangedevent/index.md)
- [InstanceStoppedEvent](https://docs.interop.io/desktop/reference/javascript/apps/instancestoppedevent/index.md)
- [RestartInstanceOptions](https://docs.interop.io/desktop/reference/javascript/apps/restartinstanceoptions/index.md)
- [StartAppOptions](https://docs.interop.io/desktop/reference/javascript/apps/startappoptions/index.md)
- [StopInstanceOptions](https://docs.interop.io/desktop/reference/javascript/apps/stopinstanceoptions/index.md)
- [UnsubscribeFunction](https://docs.interop.io/desktop/reference/javascript/search/unsubscribefunction/index.md)
