# WorkerSolver

class in `closed-chain-ik/worker`

```js
import { WorkerSolver } from 'closed-chain-ik/worker';
```

Runs the `Solver` asynchronously in a WebWorker. The worker owns a copy of the frames and the
resulting joint values are copied back onto the frames on the main thread as solves complete.

> **Warning:** When `SharedArrayBuffer` is not available a new `ArrayBuffer` is copied to the worker
on every update and back with every result.

## Constructor

```js
new WorkerSolver( roots: Frame | Array<Frame> )
```

- `roots`, `Frame | Array<Frame>`: The roots of the trees to solve.

## Properties

### .roots: Array<Frame>

The roots to solve for. If modified `updateStructure` must be called.

### .status: Array<number>

readonly

The `SOLVE_STATUS` of each chain from the most recent solve in the worker.

### .running: boolean

readonly

Whether a solve is running in the worker.

## Methods

### .updateStructure

```js
.updateStructure(  )
```

Sends the structure of the trees to the worker. Must be called whenever the parent child
structure, the degrees of freedom of a joint, or the joint values are changed on the main
thread.

### .updateSolverSettings

```js
.updateSolverSettings( settings: Object )
```

Sets the given `Solver` options on the solver in the worker.

- `settings`, `Object`: Option names and values as listed on `Solver`.

### .updateFrameState

```js
.updateFrameState( ...frames: Frame )
```

Copies the frame transforms and joint settings, everything except the joint values being
solved for, to the worker. Copies every frame if none are given.

- `frames`, `Frame`: The frames to copy.

### .solve

```js
.solve(  )
```

Starts a solve loop in the worker if one is not running. The loop stops on its own once no
chain returns `SOLVE_STATUS.TIMEOUT`.

### .stop

```js
.stop(  )
```

Stops the solve loop in the worker.

### .dispose

```js
.dispose(  )
```

Stops the solve loop and terminates the worker.
