kotlinx-coroutines-core
Core primitives to work with coroutines.
Coroutine builder functions:
Name | Result | Scope | Description |
---|---|---|---|
launch | Job | CoroutineScope | Launches coroutine that does not have any result |
async | Deferred | CoroutineScope | Returns a single value with the future result |
produce | ReceiveChannel | ProducerScope | Produces a stream of elements |
kotlinx.coroutines.runBlocking | T | CoroutineScope | Blocks the thread while the coroutine runs |
Coroutine dispatchers implementing CoroutineDispatcher:
Name | Description |
---|---|
Dispatchers.Default | Confines coroutine execution to a shared pool of background threads |
Dispatchers.Unconfined | Does not confine coroutine execution in any way |
More context elements:
Name | Description |
---|---|
NonCancellable | A non-cancelable job that is always active |
CoroutineExceptionHandler | Handler for uncaught exception |
Synchronization primitives for coroutines:
Name | Suspending functions | Description |
---|---|---|
Mutex | lock | Mutual exclusion |
Channel | send, receive | Communication channel (aka queue or exchanger) |
Top-level suspending functions:
Name | Description |
---|---|
delay | Non-blocking sleep |
yield | Yields thread in single-threaded dispatchers |
withContext | Switches to a different context |
withTimeout | Set execution time-limit with exception on timeout |
withTimeoutOrNull | Set execution time-limit will null result on timeout |
awaitAll | Awaits for successful completion of all given jobs or exceptional completion of any |
joinAll | Joins on all given jobs |
Cancellation support for user-defined suspending functions is available with suspendCancellableCoroutine helper function. NonCancellable job object is provided to suppress cancellation with withContext(NonCancellable) {...}
block of code.
Select expression waits for the result of multiple suspending functions simultaneously:
Receiver | Suspending function | Select clause | Non-suspending version |
---|---|---|---|
Job | join | onJoin | isCompleted |
Deferred | await | onAwait | isCompleted |
SendChannel | send | onSend | trySend |
ReceiveChannel | receive | onReceive | tryReceive |
ReceiveChannel | kotlinx.coroutines.channels.receiveCatching | kotlinx.coroutines.channels.onReceiveCatching | tryReceive |
none | delay | onTimeout | none |
Core primitives to work with coroutines.
Coroutine builder functions:
Name | Result | Scope | Description |
---|---|---|---|
launch | Job | CoroutineScope | Launches coroutine that does not have any result |
async | Deferred | CoroutineScope | Returns a single value with the future result |
produce | ReceiveChannel | ProducerScope | Produces a stream of elements |
runBlocking | T | CoroutineScope | Blocks the thread while the coroutine runs |
Coroutine dispatchers implementing CoroutineDispatcher:
Name | Description |
---|---|
Dispatchers.Default | Confines coroutine execution to a shared pool of background threads |
Dispatchers.Unconfined | Does not confine coroutine execution in any way |
More context elements:
Name | Description |
---|---|
NonCancellable | A non-cancelable job that is always active |
CoroutineExceptionHandler | Handler for uncaught exception |
Synchronization primitives for coroutines:
Name | Suspending functions | Description |
---|---|---|
Mutex | lock | Mutual exclusion |
Channel | send, receive | Communication channel (aka queue or exchanger) |
Top-level suspending functions:
Name | Description |
---|---|
delay | Non-blocking sleep |
yield | Yields thread in single-threaded dispatchers |
withContext | Switches to a different context |
withTimeout | Set execution time-limit with exception on timeout |
withTimeoutOrNull | Set execution time-limit will null result on timeout |
awaitAll | Awaits for successful completion of all given jobs or exceptional completion of any |
joinAll | Joins on all given jobs |
Cancellation support for user-defined suspending functions is available with suspendCancellableCoroutine helper function. NonCancellable job object is provided to suppress cancellation with withContext(NonCancellable) {...}
block of code.
Select expression waits for the result of multiple suspending functions simultaneously:
Receiver | Suspending function | Select clause | Non-suspending version |
---|---|---|---|
Job | join | onJoin | isCompleted |
Deferred | await | onAwait | isCompleted |
SendChannel | send | onSend | trySend |
ReceiveChannel | receive | onReceive | tryReceive |
ReceiveChannel | kotlinx.coroutines.channels.receiveCatching | kotlinx.coroutines.channels.onReceiveCatching | tryReceive |
none | delay | onTimeout | none |
Core primitives to work with coroutines.
Coroutine builder functions:
Name | Result | Scope | Description |
---|---|---|---|
kotlinx.coroutines.launch | kotlinx.coroutines.Job | kotlinx.coroutines.CoroutineScope | Launches coroutine that does not have any result |
kotlinx.coroutines.async | kotlinx.coroutines.Deferred | kotlinx.coroutines.CoroutineScope | Returns a single value with the future result |
kotlinx.coroutines.channels.produce | kotlinx.coroutines.channels.ReceiveChannel | kotlinx.coroutines.channels.ProducerScope | Produces a stream of elements |
runBlocking | T | kotlinx.coroutines.CoroutineScope | Blocks the thread while the coroutine runs |
Coroutine dispatchers implementing CoroutineDispatcher:
Name | Description |
---|---|
Dispatchers.Default | Confines coroutine execution to a shared pool of background threads |
Dispatchers.Unconfined | Does not confine coroutine execution in any way |
More context elements:
Name | Description |
---|---|
kotlinx.coroutines.NonCancellable | A non-cancelable job that is always active |
kotlinx.coroutines.CoroutineExceptionHandler | Handler for uncaught exception |
Synchronization primitives for coroutines:
Name | Suspending functions | Description |
---|---|---|
kotlinx.coroutines.sync.Mutex | kotlinx.coroutines.sync.Mutex.lock | Mutual exclusion |
kotlinx.coroutines.channels.Channel | kotlinx.coroutines.channels.SendChannel.send, kotlinx.coroutines.channels.ReceiveChannel.receive | Communication channel (aka queue or exchanger) |
Top-level suspending functions:
Name | Description |
---|---|
kotlinx.coroutines.delay | Non-blocking sleep |
kotlinx.coroutines.yield | Yields thread in single-threaded dispatchers |
kotlinx.coroutines.withContext | Switches to a different context |
kotlinx.coroutines.withTimeout | Set execution time-limit with exception on timeout |
kotlinx.coroutines.withTimeoutOrNull | Set execution time-limit will null result on timeout |
kotlinx.coroutines.awaitAll | Awaits for successful completion of all given jobs or exceptional completion of any |
kotlinx.coroutines.joinAll | Joins on all given jobs |
Cancellation support for user-defined suspending functions is available with suspendCancellableCoroutine helper function. NonCancellable job object is provided to suppress cancellation with withContext(NonCancellable) {...}
block of code.
kotlinx.coroutines.selects.select expression waits for the result of multiple suspending functions simultaneously:
Receiver | Suspending function | Select clause | Non-suspending version |
---|---|---|---|
kotlinx.coroutines.Job | kotlinx.coroutines.Job.join | kotlinx.coroutines.Job.onJoin | kotlinx.coroutines.Job.isCompleted |
kotlinx.coroutines.Deferred | kotlinx.coroutines.Deferred.await | kotlinx.coroutines.Deferred.onAwait | kotlinx.coroutines.Job.isCompleted |
kotlinx.coroutines.channels.SendChannel | kotlinx.coroutines.channels.SendChannel.send | kotlinx.coroutines.channels.SendChannel.onSend | kotlinx.coroutines.channels.SendChannel.trySend |
kotlinx.coroutines.channels.ReceiveChannel | kotlinx.coroutines.channels.ReceiveChannel.receive | kotlinx.coroutines.channels.ReceiveChannel.onReceive | kotlinx.coroutines.channels.ReceiveChannel.tryReceive |
kotlinx.coroutines.channels.ReceiveChannel | kotlinx.coroutines.channels.receiveCatching | kotlinx.coroutines.channels.onReceiveCatching | kotlinx.coroutines.channels.ReceiveChannel.tryReceive |
none | kotlinx.coroutines.delay | kotlinx.coroutines.selects.SelectBuilder.onTimeout | none |
Core primitives to work with coroutines.
Coroutine builder functions:
Name | Result | Scope | Description |
---|---|---|---|
launch | Job | CoroutineScope | Launches coroutine that does not have any result |
async | Deferred | CoroutineScope | Returns a single value with the future result |
produce | ReceiveChannel | ProducerScope | Produces a stream of elements |
kotlinx.coroutines.runBlocking | T | CoroutineScope | Blocks the thread while the coroutine runs |
Coroutine dispatchers implementing CoroutineDispatcher:
Name | Description |
---|---|
Dispatchers.Default | Confines coroutine execution to a shared pool of background threads |
Dispatchers.Unconfined | Does not confine coroutine execution in any way |
More context elements:
Name | Description |
---|---|
NonCancellable | A non-cancelable job that is always active |
CoroutineExceptionHandler | Handler for uncaught exception |
Synchronization primitives for coroutines:
Name | Suspending functions | Description |
---|---|---|
Mutex | lock | Mutual exclusion |
Channel | send, receive | Communication channel (aka queue or exchanger) |
Top-level suspending functions:
Name | Description |
---|---|
delay | Non-blocking sleep |
yield | Yields thread in single-threaded dispatchers |
withContext | Switches to a different context |
withTimeout | Set execution time-limit with exception on timeout |
withTimeoutOrNull | Set execution time-limit will null result on timeout |
awaitAll | Awaits for successful completion of all given jobs or exceptional completion of any |
joinAll | Joins on all given jobs |
Cancellation support for user-defined suspending functions is available with suspendCancellableCoroutine helper function. NonCancellable job object is provided to suppress cancellation with withContext(NonCancellable) {...}
block of code.
Select expression waits for the result of multiple suspending functions simultaneously:
Receiver | Suspending function | Select clause | Non-suspending version |
---|---|---|---|
Job | join | onJoin | isCompleted |
Deferred | await | onAwait | isCompleted |
SendChannel | send | onSend | trySend |
ReceiveChannel | receive | onReceive | tryReceive |
ReceiveChannel | kotlinx.coroutines.channels.receiveCatching | kotlinx.coroutines.channels.onReceiveCatching | tryReceive |
none | delay | onTimeout | none |
Core primitives to work with coroutines.
Coroutine builder functions:
Name | Result | Scope | Description |
---|---|---|---|
launch | Job | CoroutineScope | Launches coroutine that does not have any result |
async | Deferred | CoroutineScope | Returns a single value with the future result |
produce | ReceiveChannel | ProducerScope | Produces a stream of elements |
runBlocking | T | CoroutineScope | Blocks the thread while the coroutine runs |
Coroutine dispatchers implementing CoroutineDispatcher:
Name | Description |
---|---|
Dispatchers.Default | Confines coroutine execution to a shared pool of background threads |
Dispatchers.Unconfined | Does not confine coroutine execution in any way |
More context elements:
Name | Description |
---|---|
NonCancellable | A non-cancelable job that is always active |
CoroutineExceptionHandler | Handler for uncaught exception |
Synchronization primitives for coroutines:
Name | Suspending functions | Description |
---|---|---|
Mutex | lock | Mutual exclusion |
Channel | send, receive | Communication channel (aka queue or exchanger) |
Top-level suspending functions:
Name | Description |
---|---|
delay | Non-blocking sleep |
yield | Yields thread in single-threaded dispatchers |
withContext | Switches to a different context |
withTimeout | Set execution time-limit with exception on timeout |
withTimeoutOrNull | Set execution time-limit will null result on timeout |
awaitAll | Awaits for successful completion of all given jobs or exceptional completion of any |
joinAll | Joins on all given jobs |
Cancellation support for user-defined suspending functions is available with suspendCancellableCoroutine helper function. NonCancellable job object is provided to suppress cancellation with withContext(NonCancellable) {...}
block of code.
Select expression waits for the result of multiple suspending functions simultaneously:
Receiver | Suspending function | Select clause | Non-suspending version |
---|---|---|---|
Job | join | onJoin | isCompleted |
Deferred | await | onAwait | isCompleted |
SendChannel | send | onSend | trySend |
ReceiveChannel | receive | onReceive | tryReceive |
ReceiveChannel | kotlinx.coroutines.channels.receiveCatching | kotlinx.coroutines.channels.onReceiveCatching | tryReceive |
none | delay | onTimeout | none |
Core primitives to work with coroutines.
Coroutine builder functions:
Name | Result | Scope | Description |
---|---|---|---|
launch | Job | CoroutineScope | Launches coroutine that does not have any result |
async | Deferred | CoroutineScope | Returns a single value with the future result |
produce | ReceiveChannel | ProducerScope | Produces a stream of elements |
runBlocking | T | CoroutineScope | Blocks the thread while the coroutine runs |
Coroutine dispatchers implementing CoroutineDispatcher:
Name | Description |
---|---|
Dispatchers.Default | Confines coroutine execution to a shared pool of background threads |
Dispatchers.Unconfined | Does not confine coroutine execution in any way |
More context elements:
Name | Description |
---|---|
NonCancellable | A non-cancelable job that is always active |
CoroutineExceptionHandler | Handler for uncaught exception |
Synchronization primitives for coroutines:
Name | Suspending functions | Description |
---|---|---|
Mutex | lock | Mutual exclusion |
Channel | send, receive | Communication channel (aka queue or exchanger) |
Top-level suspending functions:
Name | Description |
---|---|
delay | Non-blocking sleep |
yield | Yields thread in single-threaded dispatchers |
withContext | Switches to a different context |
withTimeout | Set execution time-limit with exception on timeout |
withTimeoutOrNull | Set execution time-limit will null result on timeout |
awaitAll | Awaits for successful completion of all given jobs or exceptional completion of any |
joinAll | Joins on all given jobs |
Cancellation support for user-defined suspending functions is available with suspendCancellableCoroutine helper function. NonCancellable job object is provided to suppress cancellation with withContext(NonCancellable) {...}
block of code.
Select expression waits for the result of multiple suspending functions simultaneously:
Receiver | Suspending function | Select clause | Non-suspending version |
---|---|---|---|
Job | join | onJoin | isCompleted |
Deferred | await | onAwait | isCompleted |
SendChannel | send | onSend | trySend |
ReceiveChannel | receive | onReceive | tryReceive |
ReceiveChannel | kotlinx.coroutines.channels.receiveCatching | kotlinx.coroutines.channels.onReceiveCatching | tryReceive |
none | delay | onTimeout | none |