A Worker manages an external R session and completes tasks.

## Details

The Worker class interacts with an external R session, and possesses methods that allow it to work with Task objects. At its core, the class is a thin wrapper around a callr::r_session object, and in fact the session object itself can be obtained by calling the get_worker_session() method. In most cases this shouldn't be necessary however, because Worker objects are typically created as part of a WorkerPool that is managed by a Queue, and those higher level structures use the methods exposed by the Worker object.

## Methods

### Method new()

Create a new worker object.

#### Returns

The worker identifier, which also the process id for the R session

### Method get_worker_state()

Retrieve the worker state.

#### Returns

A vector of two difftimes.

Retrieve the task assigned to the worker.

#### Returns

An R session object, see callr::r_session

### Method try_assign()

Attempt to assign a task to this worker. This method checks that the task and the worker are both in an appropriate state. If they are, both objects register their connection to the other. This method is intended to be called by a WorkerPool or a Queue.

#### Returns

Invisibly returns TRUE or FALSE, depending on whether the attempt was successful.

### Method try_finish()

Attempt to finish a running task politely. This method checks to see if the worker has a running task, and if so polls the R session to determine if the R process claims to be ready to return. If there is a ready-to-return task the results are read from the R process and returned to the Task object. The task status is updated, and then unassigned from the Worker. This method is intended to be called by a WorkerPool or a Queue.

#### Arguments

grace

Grace period in milliseconds. If the process is still running after this period, it will be killed.

### Method clone()

The objects of this class are cloneable with this method.

#### Usage

Worker\$clone(deep = FALSE)

#### Arguments

deep

Whether to make a deep clone.