core / pragma.jobs / BackgroundManager /

BackgroundManager #

interface BackgroundManager

Class for managing background concurrent tasks.

Functions #

NameSummary

createChild

abstract fun createChild(childName: String): BackgroundManager

Creates a new BackgroundManager that is a child of this BackgroundManager.

createChildJob

abstract fun createChildJob(): CompletableJob

Creates a kotlinx.coroutines.Job that is a child of this BackgroundManager.

fireAndForget

abstract fun fireAndForget(name: String, block: suspend CoroutineScope.() -> Unit)

Runs the block of code in the background. Will not wait for results.

fireAndForgetAll

abstract fun <T> fireAndForgetAll(name: String, collection: Collection<T>, block: suspend (T) -> Unit)

Runs the block of code in the background once for each element in the collection, passing in the element as a parameter to the block.

fireAndForgetIO

abstract fun fireAndForgetIO(name: String, block: suspend CoroutineScope.() -> Unit)

Runs the block of code in the background on kotlinx.coroutines.Dispatchers.IO.

installNewThreadPool

abstract fun installNewThreadPool(nThreads: Int, name: String)

Replaces the thread pool for this BackgroundManager with a new thread pool.

parallelActor

abstract fun <T> parallelActor(name: String, channel: ReceiveChannel<T>, block: suspend (T) -> Unit)

Runs the block of code on a new coroutine every time an element is received on channel.

runForever

abstract fun runForever(functor: suspend () -> Unit, functorDelay: Long)

Runs the functor periodically with a delay.

serialActor

abstract fun <T> serialActor(name: String, channel: ReceiveChannel<T>, block: suspend (T) -> Unit)

Runs the block of code on a single coroutine every time an element is received on channel.

shutdown

abstract suspend fun shutdown()

Shuts down this BackgroundManager. kotlin.coroutines.cancellation.CancellationException will be thrown on all children or active blocks of this BackgroundManager. This also will stop functors executed by runForever.

useMyContext

abstract suspend fun useMyContext(block: suspend CoroutineScope.() -> Unit)

Runs the block of code on the kotlin.coroutines.CoroutineContext owned by this BackgroundManager.

Properties #

NameSummary

coroutineName

abstract val coroutineName: String

Name for the BackgroundManager instance, helpful for debugging purposes.