kotlinx-coroutines-core

Core primitives to work with coroutines.

Coroutine builder functions:

NameResultScopeDescription
launchJobCoroutineScopeLaunches coroutine that does not have any result
asyncDeferredCoroutineScopeReturns a single value with the future result
produceReceiveChannelProducerScopeProduces a stream of elements
kotlinx.coroutines.runBlockingTCoroutineScopeBlocks the thread while the coroutine runs

Coroutine dispatchers implementing CoroutineDispatcher:

NameDescription
Dispatchers.DefaultConfines coroutine execution to a shared pool of background threads
Dispatchers.UnconfinedDoes not confine coroutine execution in any way

More context elements:

NameDescription
NonCancellableA non-cancelable job that is always active
CoroutineExceptionHandlerHandler for uncaught exception

Synchronization primitives for coroutines:

NameSuspending functionsDescription
MutexlockMutual exclusion
Channelsend, receiveCommunication channel (aka queue or exchanger)

Top-level suspending functions:

NameDescription
delayNon-blocking sleep
yieldYields thread in single-threaded dispatchers
withContextSwitches to a different context
withTimeoutSet execution time-limit with exception on timeout
withTimeoutOrNullSet execution time-limit will null result on timeout
awaitAllAwaits for successful completion of all given jobs or exceptional completion of any
joinAllJoins 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:

ReceiverSuspending functionSelect clauseNon-suspending version
JobjoinonJoinisCompleted
DeferredawaitonAwaitisCompleted
SendChannelsendonSendtrySend
ReceiveChannelreceiveonReceivetryReceive
ReceiveChannelkotlinx.coroutines.channels.receiveCatchingkotlinx.coroutines.channels.onReceiveCatchingtryReceive
nonedelayonTimeoutnone

Core primitives to work with coroutines.

Coroutine builder functions:

NameResultScopeDescription
launchJobCoroutineScopeLaunches coroutine that does not have any result
asyncDeferredCoroutineScopeReturns a single value with the future result
produceReceiveChannelProducerScopeProduces a stream of elements
runBlockingTCoroutineScopeBlocks the thread while the coroutine runs

Coroutine dispatchers implementing CoroutineDispatcher:

NameDescription
Dispatchers.DefaultConfines coroutine execution to a shared pool of background threads
Dispatchers.UnconfinedDoes not confine coroutine execution in any way

More context elements:

NameDescription
NonCancellableA non-cancelable job that is always active
CoroutineExceptionHandlerHandler for uncaught exception

Synchronization primitives for coroutines:

NameSuspending functionsDescription
MutexlockMutual exclusion
Channelsend, receiveCommunication channel (aka queue or exchanger)

Top-level suspending functions:

NameDescription
delayNon-blocking sleep
yieldYields thread in single-threaded dispatchers
withContextSwitches to a different context
withTimeoutSet execution time-limit with exception on timeout
withTimeoutOrNullSet execution time-limit will null result on timeout
awaitAllAwaits for successful completion of all given jobs or exceptional completion of any
joinAllJoins 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:

ReceiverSuspending functionSelect clauseNon-suspending version
JobjoinonJoinisCompleted
DeferredawaitonAwaitisCompleted
SendChannelsendonSendtrySend
ReceiveChannelreceiveonReceivetryReceive
ReceiveChannelkotlinx.coroutines.channels.receiveCatchingkotlinx.coroutines.channels.onReceiveCatchingtryReceive
nonedelayonTimeoutnone

Core primitives to work with coroutines.

Coroutine builder functions:

NameResultScopeDescription
launchJobCoroutineScopeLaunches coroutine that does not have any result
asyncDeferredCoroutineScopeReturns a single value with the future result
produceReceiveChannelProducerScopeProduces a stream of elements
kotlinx.coroutines.runBlockingTCoroutineScopeBlocks the thread while the coroutine runs

Coroutine dispatchers implementing CoroutineDispatcher:

NameDescription
Dispatchers.DefaultConfines coroutine execution to a shared pool of background threads
Dispatchers.UnconfinedDoes not confine coroutine execution in any way

More context elements:

NameDescription
NonCancellableA non-cancelable job that is always active
CoroutineExceptionHandlerHandler for uncaught exception

Synchronization primitives for coroutines:

NameSuspending functionsDescription
MutexlockMutual exclusion
Channelsend, receiveCommunication channel (aka queue or exchanger)

Top-level suspending functions:

NameDescription
delayNon-blocking sleep
yieldYields thread in single-threaded dispatchers
withContextSwitches to a different context
withTimeoutSet execution time-limit with exception on timeout
withTimeoutOrNullSet execution time-limit will null result on timeout
awaitAllAwaits for successful completion of all given jobs or exceptional completion of any
joinAllJoins 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:

ReceiverSuspending functionSelect clauseNon-suspending version
JobjoinonJoinisCompleted
DeferredawaitonAwaitisCompleted
SendChannelsendonSendtrySend
ReceiveChannelreceiveonReceivetryReceive
ReceiveChannelkotlinx.coroutines.channels.receiveCatchingkotlinx.coroutines.channels.onReceiveCatchingtryReceive
nonedelayonTimeoutnone

Core primitives to work with coroutines.

Coroutine builder functions:

NameResultScopeDescription
launchJobCoroutineScopeLaunches coroutine that does not have any result
asyncDeferredCoroutineScopeReturns a single value with the future result
produceReceiveChannelProducerScopeProduces a stream of elements
runBlockingTCoroutineScopeBlocks the thread while the coroutine runs

Coroutine dispatchers implementing CoroutineDispatcher:

NameDescription
Dispatchers.DefaultConfines coroutine execution to a shared pool of background threads
Dispatchers.UnconfinedDoes not confine coroutine execution in any way

More context elements:

NameDescription
NonCancellableA non-cancelable job that is always active
CoroutineExceptionHandlerHandler for uncaught exception

Synchronization primitives for coroutines:

NameSuspending functionsDescription
MutexlockMutual exclusion
Channelsend, receiveCommunication channel (aka queue or exchanger)

Top-level suspending functions:

NameDescription
delayNon-blocking sleep
yieldYields thread in single-threaded dispatchers
withContextSwitches to a different context
withTimeoutSet execution time-limit with exception on timeout
withTimeoutOrNullSet execution time-limit will null result on timeout
awaitAllAwaits for successful completion of all given jobs or exceptional completion of any
joinAllJoins 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:

ReceiverSuspending functionSelect clauseNon-suspending version
JobjoinonJoinisCompleted
DeferredawaitonAwaitisCompleted
SendChannelsendonSendtrySend
ReceiveChannelreceiveonReceivetryReceive
ReceiveChannelkotlinx.coroutines.channels.receiveCatchingkotlinx.coroutines.channels.onReceiveCatchingtryReceive
nonedelayonTimeoutnone

Core primitives to work with coroutines.

Coroutine builder functions:

NameResultScopeDescription
launchJobCoroutineScopeLaunches coroutine that does not have any result
asyncDeferredCoroutineScopeReturns a single value with the future result
produceReceiveChannelProducerScopeProduces a stream of elements
runBlockingTCoroutineScopeBlocks the thread while the coroutine runs

Coroutine dispatchers implementing CoroutineDispatcher:

NameDescription
Dispatchers.DefaultConfines coroutine execution to a shared pool of background threads
Dispatchers.UnconfinedDoes not confine coroutine execution in any way

More context elements:

NameDescription
NonCancellableA non-cancelable job that is always active
CoroutineExceptionHandlerHandler for uncaught exception

Synchronization primitives for coroutines:

NameSuspending functionsDescription
MutexlockMutual exclusion
Channelsend, receiveCommunication channel (aka queue or exchanger)

Top-level suspending functions:

NameDescription
delayNon-blocking sleep
yieldYields thread in single-threaded dispatchers
withContextSwitches to a different context
withTimeoutSet execution time-limit with exception on timeout
withTimeoutOrNullSet execution time-limit will null result on timeout
awaitAllAwaits for successful completion of all given jobs or exceptional completion of any
joinAllJoins 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:

ReceiverSuspending functionSelect clauseNon-suspending version
JobjoinonJoinisCompleted
DeferredawaitonAwaitisCompleted
SendChannelsendonSendtrySend
ReceiveChannelreceiveonReceivetryReceive
ReceiveChannelkotlinx.coroutines.channels.receiveCatchingkotlinx.coroutines.channels.onReceiveCatchingtryReceive
nonedelayonTimeoutnone

Packages

Link copied to clipboard
common
concurrent
js
native

General-purpose coroutine builders, contexts, and helper functions.

Link copied to clipboard
common
concurrent

Channels — non-blocking primitives for communicating a stream of elements between coroutines.

Link copied to clipboard
common

Flow — asynchronous cold stream of elements.

Link copied to clipboard
common

Low-level primitives for finer-grained control of coroutines.

Link copied to clipboard
common

Select expression to perform multiple suspending operations simultaneously until one of them succeeds.

Link copied to clipboard
common

Synchronization primitives (mutex).