Pool

value class Pool

The Pool class represents the common "thread pool," or more accurately, the common executor. The static methods of this class are the root of all parallelism in Guardian and are used to enqueue asynchronous tasks.

The underlying executor implementation is configurable at runtime, but the default implementation is a fixed-size thread pool with a thread count determined by the number of logical cores on the system. As such, the default behavior of the Pool class is to run tasks in parallel on the system's available threads, but the executor could also be configured to run tasks serially, as is the case in single-thread debugging mode.

Backend-Specific Configuration

When using the Java backend with the Javalineer implementation of Guards, the executor implementation can be selected at startup by setting the JAVALINEER_POOL environment variable. When applicable, the number of threads in the pool can be configured by setting the JAVALINEER_POOL_THREADS environment variable.

The JAVALINEER_POOL environment variable can be set to one of the following values:

API Reference

Static Methods

run<T>(task: () -> T) -> Fut<T>

Enqueues task to be run asynchronously, returning a future that will be completed with the result of task.

runFut<T>(task: () -> Fut<T>) -> Fut<T>

Enqueues task to be run asynchronously, returning a future. When the future returned by task is completed, the future returned by runFut will be completed with the same result.