tree: 5ed73887ebf36c299dce407f633fc04b80ae8b38 [path history] [tgz]
  1. src/
  2. pom.xml
  3. README.md
kotlinx-coroutines-core/README.md

Module 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
produceProducerJobProducerScopeProduces a stream of elements
actorActorJobActorScopeProcesses a stream of messages
runBlockingTCoroutineScopeBlocks the thread while the coroutine runs

Coroutine dispatchers implementing CoroutineDispatcher:

NameDescription
CommonPoolConfines coroutine execution to a shared pool of threads
newSingleThreadContextCreate new single-threaded coroutine context
newFixedThreadPoolContextCreates new thread pool of a fixed size
Executor.asCoroutineDispatcherExtension to convert any executor
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
runSwitches to a different context
withTimeoutSet execution time-limit with exception on timeout
withTimeoutOrNullSet execution time-limit will null result on timeout

Select expression waits for the result of multiple suspending functions simultaneously:

ReceiverSuspending functionSelect clauseNon-suspending version
JobjoinonJoinisCompleted
DeferredawaitonAwaitisCompleted
SendChannelsendonSendoffer
ReceiveChannelreceiveonReceivepoll
ReceiveChannelreceiveOrNullonReceiveOrNullpoll
MutexlockonLocktryLock
nonedelayonTimeoutnone

Cancellation support for user-defined suspending functions is available with suspendCancellableCoroutine helper function. NonCancellable job object is provided to suppress cancellation with run(NonCancellable) {...} block of code.

This module provides debugging facilities for coroutines (run JVM with -ea or -Dkotlinx.coroutines.debug options) and newCoroutineContext function to write user-defined coroutine builders that work with these debugging facilities.

Package kotlinx.coroutines.experimental

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

Package kotlinx.coroutines.experimental.sync

Synchronization primitives (mutex).

Package kotlinx.coroutines.experimental.channels

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

Package kotlinx.coroutines.experimental.selects

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