aosp12/external/kotlinx.coroutines/kotlinx-coroutines-core
hcl 7be3fd486c init from android-12.1.0_r8 2023-01-09 17:11:35 +08:00
..
api init from android-12.1.0_r8 2023-01-09 17:11:35 +08:00
common init from android-12.1.0_r8 2023-01-09 17:11:35 +08:00
js init from android-12.1.0_r8 2023-01-09 17:11:35 +08:00
jvm init from android-12.1.0_r8 2023-01-09 17:11:35 +08:00
native init from android-12.1.0_r8 2023-01-09 17:11:35 +08:00
nativeDarwin init from android-12.1.0_r8 2023-01-09 17:11:35 +08:00
nativeOther init from android-12.1.0_r8 2023-01-09 17:11:35 +08:00
npm init from android-12.1.0_r8 2023-01-09 17:11:35 +08:00
README.md init from android-12.1.0_r8 2023-01-09 17:11:35 +08:00
build.gradle init from android-12.1.0_r8 2023-01-09 17:11:35 +08:00
knit.properties init from android-12.1.0_r8 2023-01-09 17:11:35 +08:00

README.md

Module 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
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 offer
ReceiveChannel receive onReceive poll
ReceiveChannel receiveOrNull onReceiveOrNull poll
Mutex lock onLock tryLock
none delay onTimeout none

Package kotlinx.coroutines

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

Package kotlinx.coroutines.sync

Synchronization primitives (mutex).

Package kotlinx.coroutines.channels

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

Package kotlinx.coroutines.flow

Flow — asynchronous cold stream of elements.

Package kotlinx.coroutines.selects

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

Package kotlinx.coroutines.intrinsics

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

Package kotlinx.coroutines.test

Obsolete and deprecated module to test coroutines. Replaced with kotlinx-coroutines-test module.