Package org.gradle.workers

# Interface WorkerExecutor

@Incubating public interface WorkerExecutor
Allows work to be submitted for asynchronous execution. This api allows for safe, concurrent execution of work items and enables:

- Parallel execution of work items within a single task
- Execution in isolated contexts such as an isolated classloader or even a separate process
- Safe execution of multiple tasks in parallel

Work should be submitted with a `Runnable` class representing the implementation of the unit of work and an action to configure the unit of work (via `WorkerConfiguration`).

          workerExecutor.submit(RunnableWorkImpl.class) { WorkerConfiguration conf ->
              // Set the isolation mode for the worker
              conf.isolationMode = IsolationMode.NONE

              // Set up the constructor parameters for the unit of work
              conf.params = [ "foo", file('bar') ]
          }

Since:
  3.5

## Method Summary

Modifier and Type
Method
Description
`void`
`await()`
Blocks until all work associated with the current build operation is complete.
`void`
`submit(Class<? extends Runnable> actionClass, Action<? super WorkerConfiguration> configAction)`
Submits a piece of work to be executed asynchronously.

## Method Details

### submit

void submit(Class<? extends Runnable> actionClass, Action<? super WorkerConfiguration> configAction)
Submits a piece of work to be executed asynchronously. Execution of the work may begin immediately. Work configured with `IsolationMode.PROCESS` will execute in an idle daemon that meets the requirements set in the `WorkerConfiguration`. If no idle daemons are available, a new daemon will be started. Any errors will be thrown from `await()` or from the surrounding task action if `await()` is not used.

### await

void await() throws WorkerExecutionException
Blocks until all work associated with the current build operation is complete. Note that when using this method inside a task action, it will block completion of the task action until all submitted work is complete. This means that other tasks from the same project cannot be run in parallel while the task action is still executing.

Throws:
  `WorkerExecutionException` - when a failure occurs while executing the work.