Worker

inline class Worker

Class representing worker.

Types

Companion
Link copied to clipboard
object Companion

Functions

asCPointer
Link copied to clipboard
fun asCPointer(): COpaquePointer?

Convert worker to a COpaquePointer value that could be passed via native void* pointer. Can be used as an argument of Worker.fromCPointer.

execute
Link copied to clipboard
fun <T1, T2> execute(mode: TransferMode, producer: () -> T1, job: (T1) -> T2): Future<T2>

Plan job for further execution in the worker. Execute is a two-phase operation:

executeAfter
Link copied to clipboard
fun executeAfter(afterMicroseconds: Long = 0, operation: () -> Unit)

Plan job for further execution in the worker. operation parameter must be either frozen, or execution to be planned on the current worker. Otherwise IllegalStateException will be thrown.

park
Link copied to clipboard
fun park(timeoutMicroseconds: Long, process: Boolean = false): Boolean

Park execution of the current worker until a new request arrives or timeout specified in timeoutMicroseconds elapsed. If process is true, pending queue elements are processed, including delayed requests. Note that multiple requests could be processed this way.

processQueue
Link copied to clipboard
fun processQueue(): Boolean

Process pending job(s) on the queue of this worker. Note that jobs scheduled with executeAfter using non-zero timeout are not processed this way. If termination request arrives while processing the queue via this API, worker is marked as terminated and will exit once the current request is done with.

requestTermination
Link copied to clipboard
fun requestTermination(processScheduledJobs: Boolean = true): Future<Unit>

Requests termination of the worker.

toString
Link copied to clipboard
open override fun toString(): String

String representation of the worker.

Properties

id
Link copied to clipboard
val id: Int
name
Link copied to clipboard
val name: String

Name of the worker, as specified in Worker.start or "worker $id" by default,