BackgroundWorker

class BackgroundWorker(worker: Worker) : Worker

Functions

equals
Link copied to clipboard
ios
open operator override fun equals(other: Any?): Boolean
execute
Link copied to clipboard
ios

Executes a non capturing lambda job with jobInput as its arguments.

Returns a Future of type V

open override fun <T, V> execute(jobInput: T, job: (T) -> V): Future<V>
executeAndResume
Link copied to clipboard
ios

Executes a job the current instance with jobInput as input and then invokes the resumingJob closure on the resumingWorker worker. The resumingJob closure accepts the output of job as the only argument. Both job and resumingJob closures must be non capturing lambdas. The job can be resumed on a different worker by passing resumingWorker argument which is set to the current worker by default. The awaitResumingJob blocks the current instance until resumingJob block is finished. This is useful in testing.

For example

// in main thread
worker.execute("input", {

// executes in worker 1
"$it-processed"
}) {
// executes on main thread
println(it) // prints "$it-processed"
}

open override fun <T, V, W> executeAndResume(jobInput: T, job: (T) -> V, resumingWorker: Worker, awaitResumingJob: Boolean, resumingJob: (V) -> W): Future<V>
hashCode
Link copied to clipboard
ios
open override fun hashCode(): Int
terminate
Link copied to clipboard
ios

Terminates the worker. The pending tasks can be allowed to finish by passing finishPendingTasks as true. If false is passed, the worker is terminated immediately.

Returns a future which resolves when the worker has been terminated.

Note that the future blocks the calling thread. So a rogue scheduled task may hang the calling thread infinitely if finishPendingTasks is true.

open override fun terminate(finishPendingTasks: Boolean): Future<Unit>
toString
Link copied to clipboard
ios
open override fun toString(): String

Properties

id
Link copied to clipboard
ios

Returns the identifier of this Worker.

open override val id: Long