From 6c1cfb79b9c1a24845498782568d71ebe7396bfd Mon Sep 17 00:00:00 2001 From: zoobestik Date: Mon, 27 Jun 2022 15:42:38 +0300 Subject: [PATCH] feat; moved pages to kotlinlang.org --- README.md | 1 + index.html | 255 +- kotlinx-coroutines-android/index.html | 73 +- .../-handler-dispatcher/immediate.html | 55 +- .../-handler-dispatcher/index.html | 77 +- .../as-coroutine-dispatcher.html | 55 +- .../await-frame.html | 55 +- .../kotlinx.coroutines.android/index.html | 109 +- kotlinx-coroutines-android/navigation.html | 2047 ----------------- kotlinx-coroutines-core/index.html | 192 +- .../-actor-scope/channel.html | 73 +- .../-actor-scope/index.html | 97 +- .../-broadcast-channel.html | 73 +- .../-broadcast-channel/cancel.html | 73 +- .../-broadcast-channel/index.html | 180 +- .../-broadcast-channel/open-subscription.html | 73 +- .../-d-r-o-p_-l-a-t-e-s-t/index.html | 64 +- .../-d-r-o-p_-o-l-d-e-s-t/index.html | 64 +- .../-s-u-s-p-e-n-d/index.html | 64 +- .../-buffer-overflow/index.html | 131 +- .../-channel-iterator/has-next.html | 73 +- .../-channel-iterator/index.html | 131 +- .../-channel-iterator/next.html | 73 +- .../-channel-iterator/next0.html | 73 +- .../-channel-result/-companion/closed.html | 73 +- .../-channel-result/-companion/failure.html | 73 +- .../-channel-result/-companion/index.html | 131 +- .../-channel-result/-companion/success.html | 73 +- .../-channel-result/exception-or-null.html | 73 +- .../-channel-result/get-or-null.html | 73 +- .../-channel-result/get-or-throw.html | 73 +- .../-channel-result/index.html | 290 +-- .../-channel-result/is-closed.html | 73 +- .../-channel-result/is-failure.html | 73 +- .../-channel-result/is-success.html | 73 +- .../-channel-result/to-string.html | 73 +- .../kotlinx.coroutines.channels/-channel.html | 84 +- .../-channel/-factory/-b-u-f-f-e-r-e-d.html | 73 +- .../-channel/-factory/-c-o-n-f-l-a-t-e-d.html | 73 +- ...b-u-f-f-e-r_-p-r-o-p-e-r-t-y_-n-a-m-e.html | 73 +- .../-factory/-r-e-n-d-e-z-v-o-u-s.html | 73 +- .../-channel/-factory/-u-n-l-i-m-i-t-e-d.html | 73 +- .../-channel/-factory/index.html | 165 +- .../-channel/index.html | 97 +- .../-closed-receive-channel-exception.html | 73 +- .../index.html | 97 +- .../-closed-send-channel-exception.html | 73 +- .../-closed-send-channel-exception/index.html | 97 +- .../-conflated-broadcast-channel.html | 84 +- .../-conflated-broadcast-channel/cancel.html | 73 +- .../-conflated-broadcast-channel/close.html | 73 +- .../-conflated-broadcast-channel/index.html | 288 +-- .../invoke-on-close.html | 73 +- .../is-closed-for-send.html | 73 +- .../-conflated-broadcast-channel/on-send.html | 73 +- .../open-subscription.html | 73 +- .../-conflated-broadcast-channel/send.html | 73 +- .../try-send.html | 73 +- .../value-or-null.html | 73 +- .../-conflated-broadcast-channel/value.html | 73 +- .../-producer-scope/channel.html | 73 +- .../-producer-scope/index.html | 116 +- .../-receive-channel/cancel.html | 73 +- .../-receive-channel/index.html | 381 +-- .../is-closed-for-receive.html | 73 +- .../-receive-channel/is-empty.html | 73 +- .../-receive-channel/iterator.html | 73 +- .../-receive-channel/on-receive-catching.html | 73 +- .../-receive-channel/on-receive.html | 73 +- .../-receive-channel/receive-catching.html | 73 +- .../-receive-channel/receive.html | 73 +- .../-receive-channel/try-receive.html | 73 +- .../-send-channel/close.html | 73 +- .../-send-channel/index.html | 239 +- .../-send-channel/invoke-on-close.html | 73 +- .../-send-channel/is-closed-for-send.html | 73 +- .../-send-channel/on-send.html | 73 +- .../-send-channel/send.html | 73 +- .../-send-channel/try-send.html | 73 +- .../-f-i-x-e-d_-d-e-l-a-y/index.html | 64 +- .../-f-i-x-e-d_-p-e-r-i-o-d/index.html | 64 +- .../-ticker-mode/index.html | 114 +- .../kotlinx.coroutines.channels/actor.html | 73 +- .../await-close.html | 73 +- .../broadcast.html | 84 +- .../consume-each.html | 84 +- .../kotlinx.coroutines.channels/consume.html | 84 +- .../get-or-else.html | 73 +- .../kotlinx.coroutines.channels/index.html | 564 +---- .../on-closed.html | 73 +- .../on-failure.html | 73 +- .../on-receive-or-null.html | 73 +- .../on-success.html | 73 +- .../kotlinx.coroutines.channels/produce.html | 73 +- .../kotlinx.coroutines.channels/ticker.html | 73 +- .../kotlinx.coroutines.channels/to-list.html | 73 +- .../try-send-blocking.html | 60 +- .../-abstract-flow/-abstract-flow.html | 73 +- .../-abstract-flow/collect-safely.html | 73 +- .../-abstract-flow/collect.html | 73 +- .../-abstract-flow/index.html | 133 +- ...-d-e-f-a-u-l-t_-c-o-n-c-u-r-r-e-n-c-y.html | 73 +- ...r-r-e-n-c-y_-p-r-o-p-e-r-t-y_-n-a-m-e.html | 73 +- .../-flow-collector/emit.html | 73 +- .../-flow-collector/index.html | 129 +- .../-flow/collect.html | 73 +- .../kotlinx.coroutines.flow/-flow/index.html | 1143 +-------- .../-mutable-shared-flow.html | 73 +- .../-mutable-shared-flow/emit.html | 73 +- .../-mutable-shared-flow/index.html | 182 +- .../reset-replay-cache.html | 73 +- .../subscription-count.html | 73 +- .../-mutable-shared-flow/try-emit.html | 73 +- .../-mutable-state-flow.html | 73 +- .../-mutable-state-flow/compare-and-set.html | 73 +- .../-mutable-state-flow/index.html | 186 +- .../-mutable-state-flow/value.html | 73 +- .../-shared-flow/collect.html | 73 +- .../-shared-flow/index.html | 159 +- .../-shared-flow/replay-cache.html | 73 +- .../-sharing-command/-s-t-a-r-t/index.html | 64 +- .../-sharing-command/-s-t-o-p/index.html | 64 +- .../index.html | 64 +- .../-sharing-command/index.html | 131 +- .../-sharing-started/-companion/-eagerly.html | 73 +- .../-sharing-started/-companion/-lazily.html | 73 +- .../-companion/-while-subscribed.html | 73 +- .../-sharing-started/-companion/index.html | 152 +- .../-sharing-started/command.html | 73 +- .../-sharing-started/index.html | 116 +- .../-state-flow/index.html | 110 +- .../-state-flow/value.html | 73 +- .../-while-subscribed.html | 73 +- .../kotlinx.coroutines.flow/as-flow.html | 183 +- .../as-shared-flow.html | 73 +- .../as-state-flow.html | 73 +- .../kotlinx.coroutines.flow/buffer.html | 84 +- .../callback-flow.html | 73 +- .../kotlinx.coroutines.flow/cancellable.html | 73 +- .../kotlinx.coroutines.flow/catch.html | 73 +- .../kotlinx.coroutines.flow/channel-flow.html | 73 +- .../collect-indexed.html | 73 +- .../collect-latest.html | 73 +- .../kotlinx.coroutines.flow/collect.html | 73 +- .../combine-transform.html | 139 +- .../kotlinx.coroutines.flow/combine.html | 139 +- .../kotlinx.coroutines.flow/conflate.html | 73 +- .../consume-as-flow.html | 73 +- .../kotlinx.coroutines.flow/count.html | 84 +- .../kotlinx.coroutines.flow/debounce.html | 106 +- .../distinct-until-changed-by.html | 73 +- .../distinct-until-changed.html | 84 +- .../kotlinx.coroutines.flow/drop-while.html | 73 +- .../kotlinx.coroutines.flow/drop.html | 73 +- .../kotlinx.coroutines.flow/emit-all.html | 84 +- .../kotlinx.coroutines.flow/empty-flow.html | 73 +- .../filter-is-instance.html | 73 +- .../filter-not-null.html | 73 +- .../kotlinx.coroutines.flow/filter-not.html | 73 +- .../kotlinx.coroutines.flow/filter.html | 73 +- .../first-or-null.html | 84 +- .../kotlinx.coroutines.flow/first.html | 84 +- .../flat-map-concat.html | 73 +- .../flat-map-latest.html | 73 +- .../flat-map-merge.html | 73 +- .../flatten-concat.html | 73 +- .../flatten-merge.html | 73 +- .../kotlinx.coroutines.flow/flow-of.html | 84 +- .../kotlinx.coroutines.flow/flow-on.html | 73 +- .../kotlinx.coroutines.flow/flow.html | 73 +- .../kotlinx.coroutines.flow/fold.html | 73 +- .../get-and-update.html | 73 +- .../kotlinx.coroutines.flow/index.html | 1601 +------------ .../kotlinx.coroutines.flow/last-or-null.html | 73 +- .../kotlinx.coroutines.flow/last.html | 73 +- .../kotlinx.coroutines.flow/launch-in.html | 73 +- .../kotlinx.coroutines.flow/map-latest.html | 73 +- .../kotlinx.coroutines.flow/map-not-null.html | 73 +- .../kotlinx.coroutines.flow/map.html | 73 +- .../kotlinx.coroutines.flow/merge.html | 84 +- .../on-completion.html | 73 +- .../kotlinx.coroutines.flow/on-each.html | 73 +- .../kotlinx.coroutines.flow/on-empty.html | 73 +- .../kotlinx.coroutines.flow/on-start.html | 73 +- .../on-subscription.html | 73 +- .../kotlinx.coroutines.flow/produce-in.html | 73 +- .../receive-as-flow.html | 73 +- .../kotlinx.coroutines.flow/reduce.html | 73 +- .../kotlinx.coroutines.flow/retry-when.html | 73 +- .../kotlinx.coroutines.flow/retry.html | 73 +- .../kotlinx.coroutines.flow/running-fold.html | 73 +- .../running-reduce.html | 73 +- .../kotlinx.coroutines.flow/sample.html | 84 +- .../kotlinx.coroutines.flow/scan.html | 73 +- .../kotlinx.coroutines.flow/share-in.html | 73 +- .../single-or-null.html | 73 +- .../kotlinx.coroutines.flow/single.html | 73 +- .../kotlinx.coroutines.flow/state-in.html | 84 +- .../kotlinx.coroutines.flow/take-while.html | 73 +- .../kotlinx.coroutines.flow/take.html | 73 +- .../to-collection.html | 73 +- .../kotlinx.coroutines.flow/to-list.html | 73 +- .../kotlinx.coroutines.flow/to-set.html | 73 +- .../transform-latest.html | 73 +- .../transform-while.html | 73 +- .../kotlinx.coroutines.flow/transform.html | 73 +- .../update-and-get.html | 73 +- .../kotlinx.coroutines.flow/update.html | 73 +- .../kotlinx.coroutines.flow/with-index.html | 73 +- .../kotlinx.coroutines.flow/zip.html | 73 +- .../kotlinx.coroutines.intrinsics/index.html | 84 +- .../start-coroutine-cancellable.html | 73 +- .../-select-builder/index.html | 133 +- .../-select-builder/invoke.html | 106 +- .../-select-builder/on-timeout.html | 73 +- .../-select-clause0/index.html | 78 +- .../-select-clause1/index.html | 78 +- .../-select-clause2/index.html | 78 +- .../kotlinx.coroutines.selects/index.html | 205 +- .../on-timeout.html | 73 +- .../select-unbiased.html | 73 +- .../kotlinx.coroutines.selects/select.html | 73 +- .../while-select.html | 73 +- .../kotlinx.coroutines.sync/-mutex.html | 73 +- .../-mutex/holds-lock.html | 73 +- .../kotlinx.coroutines.sync/-mutex/index.html | 203 +- .../-mutex/is-locked.html | 73 +- .../kotlinx.coroutines.sync/-mutex/lock.html | 73 +- .../-mutex/on-lock.html | 73 +- .../-mutex/try-lock.html | 73 +- .../-mutex/unlock.html | 73 +- .../kotlinx.coroutines.sync/-semaphore.html | 73 +- .../-semaphore/acquire.html | 73 +- .../-semaphore/available-permits.html | 73 +- .../-semaphore/index.html | 169 +- .../-semaphore/release.html | 73 +- .../-semaphore/try-acquire.html | 73 +- .../kotlinx.coroutines.sync/index.html | 171 +- .../kotlinx.coroutines.sync/with-lock.html | 73 +- .../kotlinx.coroutines.sync/with-permit.html | 73 +- .../-cancellable-continuation/cancel.html | 73 +- .../-cancellable-continuation/index.html | 238 +- .../invoke-on-cancellation.html | 73 +- .../-cancellable-continuation/is-active.html | 73 +- .../is-cancelled.html | 73 +- .../is-completed.html | 73 +- .../resume-undispatched-with-exception.html | 73 +- .../resume-undispatched.html | 73 +- .../-cancellable-continuation/resume.html | 73 +- .../-cancellation-exception.html | 85 +- .../-cancellation-exception.html | 73 +- .../-cancellation-exception/index.html | 113 +- .../-closeable-coroutine-dispatcher.html | 97 +- .../close.html | 97 +- .../index.html | 141 +- .../-completable-deferred.html | 84 +- .../complete-exceptionally.html | 73 +- .../-completable-deferred/complete.html | 73 +- .../-completable-deferred/index.html | 133 +- .../complete-exceptionally.html | 73 +- .../-completable-job/complete.html | 73 +- .../-completable-job/index.html | 114 +- .../copy-for-child.html | 73 +- .../index.html | 114 +- .../merge-for-child.html | 73 +- .../-copyable-throwable/create-copy.html | 73 +- .../-copyable-throwable/index.html | 110 +- .../-coroutine-dispatcher.html | 73 +- .../-coroutine-dispatcher/dispatch.html | 73 +- .../-coroutine-dispatcher/index.html | 258 +-- .../intercept-continuation.html | 73 +- .../is-dispatch-needed.html | 73 +- .../limited-parallelism.html | 73 +- .../release-intercepted-continuation.html | 73 +- .../-coroutine-exception-handler.html | 73 +- .../-key/index.html | 78 +- .../handle-exception.html | 73 +- .../-coroutine-exception-handler/index.html | 116 +- .../-coroutine-name/-coroutine-name.html | 73 +- .../-coroutine-name/-key/index.html | 78 +- .../-coroutine-name/index.html | 154 +- .../-coroutine-name/name.html | 73 +- .../-coroutine-name/to-string.html | 73 +- .../kotlinx.coroutines/-coroutine-scope.html | 73 +- .../-coroutine-scope/coroutine-context.html | 73 +- .../-coroutine-scope/index.html | 324 +-- .../-coroutine-start/-a-t-o-m-i-c/index.html | 64 +- .../-d-e-f-a-u-l-t/index.html | 64 +- .../-coroutine-start/-l-a-z-y/index.html | 64 +- .../-u-n-d-i-s-p-a-t-c-h-e-d/index.html | 64 +- .../-coroutine-start/index.html | 148 +- .../-d-e-b-u-g_-p-r-o-p-e-r-t-y_-n-a-m-e.html | 73 +- ..._-p-r-o-p-e-r-t-y_-v-a-l-u-e_-a-u-t-o.html | 73 +- ...-g_-p-r-o-p-e-r-t-y_-v-a-l-u-e_-o-f-f.html | 73 +- ...-u-g_-p-r-o-p-e-r-t-y_-v-a-l-u-e_-o-n.html | 73 +- .../kotlinx.coroutines/-deferred/await.html | 73 +- .../-deferred/get-completed.html | 73 +- .../get-completion-exception-or-null.html | 73 +- .../kotlinx.coroutines/-deferred/index.html | 183 +- .../-deferred/on-await.html | 73 +- .../-delicate-coroutines-api.html | 73 +- .../-delicate-coroutines-api/index.html | 97 +- .../-dispatchers/-default.html | 109 +- .../kotlinx.coroutines/-dispatchers/-i-o.html | 73 +- .../-dispatchers/-main.html | 109 +- .../-dispatchers/-unconfined.html | 109 +- .../-dispatchers/index.html | 203 +- .../-dispatchers/shutdown.html | 73 +- .../-disposable-handle/dispose.html | 73 +- .../-disposable-handle/index.html | 97 +- .../-executor-coroutine-dispatcher.html | 73 +- .../-executor-coroutine-dispatcher/close.html | 73 +- .../executor.html | 73 +- .../-executor-coroutine-dispatcher/index.html | 135 +- .../-experimental-coroutines-api.html | 73 +- .../-experimental-coroutines-api/index.html | 97 +- .../-flow-preview/-flow-preview.html | 73 +- .../-flow-preview/index.html | 97 +- .../-global-scope/coroutine-context.html | 73 +- .../-global-scope/index.html | 97 +- ...l-e-l-i-s-m_-p-r-o-p-e-r-t-y_-n-a-m-e.html | 73 +- .../-internal-coroutines-api.html | 73 +- .../-internal-coroutines-api/index.html | 97 +- .../kotlinx.coroutines/-job.html | 73 +- .../kotlinx.coroutines/-job/-key/index.html | 78 +- .../kotlinx.coroutines/-job/cancel.html | 73 +- .../kotlinx.coroutines/-job/children.html | 73 +- .../kotlinx.coroutines/-job/index.html | 359 +-- .../-job/invoke-on-completion.html | 73 +- .../kotlinx.coroutines/-job/is-active.html | 73 +- .../kotlinx.coroutines/-job/is-cancelled.html | 73 +- .../kotlinx.coroutines/-job/is-completed.html | 73 +- .../kotlinx.coroutines/-job/join.html | 73 +- .../kotlinx.coroutines/-job/on-join.html | 73 +- .../kotlinx.coroutines/-job/start.html | 73 +- .../-main-coroutine-dispatcher.html | 73 +- .../-main-coroutine-dispatcher/immediate.html | 73 +- .../-main-coroutine-dispatcher/index.html | 152 +- .../limited-parallelism.html | 73 +- .../-main-coroutine-dispatcher/to-string.html | 73 +- .../kotlinx.coroutines/-main-scope.html | 73 +- .../-non-cancellable/index.html | 78 +- .../-obsolete-coroutines-api.html | 73 +- .../-obsolete-coroutines-api/index.html | 97 +- .../kotlinx.coroutines/-runnable.html | 109 +- .../kotlinx.coroutines/-runnable/index.html | 103 +- .../kotlinx.coroutines/-supervisor-job.html | 73 +- .../-thread-context-element/index.html | 127 +- .../restore-thread-context.html | 73 +- .../update-thread-context.html | 73 +- .../create-copy.html | 73 +- .../index.html | 97 +- .../as-context-element.html | 73 +- .../as-coroutine-dispatcher.html | 96 +- .../kotlinx.coroutines/as-deferred.html | 73 +- .../kotlinx.coroutines/as-executor.html | 73 +- .../kotlinx.coroutines/as-promise.html | 73 +- .../kotlinx.coroutines/async.html | 73 +- .../kotlinx.coroutines/await-all.html | 84 +- .../await-animation-frame.html | 73 +- .../await-cancellation.html | 73 +- .../kotlinx.coroutines/await.html | 73 +- .../kotlinx.coroutines/cancel-and-join.html | 73 +- .../kotlinx.coroutines/cancel-children.html | 84 +- .../cancel-future-on-cancellation.html | 73 +- .../kotlinx.coroutines/cancel.html | 106 +- .../kotlinx.coroutines/complete-with.html | 73 +- .../kotlinx.coroutines/coroutine-scope.html | 73 +- .../current-coroutine-context.html | 73 +- .../kotlinx.coroutines/delay.html | 84 +- .../kotlinx.coroutines/ensure-active.html | 95 +- .../kotlinx.coroutines/ensure-present.html | 73 +- .../handle-coroutine-exception.html | 73 +- .../kotlinx.coroutines/index.html | 1452 +----------- .../kotlinx.coroutines/invoke.html | 73 +- .../kotlinx.coroutines/is-active.html | 84 +- .../kotlinx.coroutines/is-present.html | 73 +- .../kotlinx.coroutines/job.html | 73 +- .../kotlinx.coroutines/join-all.html | 84 +- .../kotlinx.coroutines/launch.html | 73 +- .../new-coroutine-context.html | 109 +- .../new-fixed-thread-pool-context.html | 86 +- .../new-single-thread-context.html | 86 +- .../kotlinx.coroutines/plus.html | 73 +- .../kotlinx.coroutines/promise.html | 73 +- .../kotlinx.coroutines/run-blocking.html | 86 +- .../kotlinx.coroutines/run-interruptible.html | 73 +- .../kotlinx.coroutines/supervisor-scope.html | 73 +- .../suspend-cancellable-coroutine.html | 73 +- .../kotlinx.coroutines/with-context.html | 73 +- .../with-timeout-or-null.html | 84 +- .../kotlinx.coroutines/with-timeout.html | 84 +- .../kotlinx.coroutines/yield.html | 73 +- kotlinx-coroutines-core/navigation.html | 2047 ----------------- kotlinx-coroutines-debug/index.html | 157 +- .../-coroutines-timeout/-companion/index.html | 77 +- .../-companion/seconds.html | 55 +- .../-coroutines-timeout.html | 55 +- .../-coroutines-timeout/index.html | 109 +- .../index.html | 76 +- .../-coroutines-timeout.html | 55 +- .../cancel-on-timeout.html | 55 +- .../-coroutines-timeout/index.html | 113 +- .../-coroutines-timeout/test-timeout-ms.html | 55 +- .../index.html | 76 +- .../-coroutine-info/context.html | 55 +- .../-coroutine-info/creation-stack-trace.html | 55 +- .../-coroutine-info/index.html | 154 +- .../-coroutine-info/job.html | 55 +- .../last-observed-stack-trace.html | 55 +- .../-coroutine-info/state.html | 55 +- .../-coroutine-info/to-string.html | 55 +- .../-coroutines-block-hound-integration.html | 55 +- .../apply-to.html | 55 +- .../index.html | 94 +- .../-debug-probes/dump-coroutines-info.html | 55 +- .../-debug-probes/dump-coroutines.html | 55 +- .../enable-creation-stack-traces.html | 55 +- .../-debug-probes/index.html | 244 +- .../-debug-probes/install.html | 55 +- .../-debug-probes/is-installed.html | 55 +- .../-debug-probes/job-to-string.html | 55 +- .../-debug-probes/print-job.html | 55 +- .../-debug-probes/print-scope.html | 55 +- .../-debug-probes/sanitize-stack-traces.html | 55 +- .../-debug-probes/scope-to-string.html | 55 +- .../-debug-probes/uninstall.html | 55 +- .../-debug-probes/with-debug-probes.html | 55 +- .../-state/-c-r-e-a-t-e-d/index.html | 59 +- .../-state/-r-u-n-n-i-n-g/index.html | 59 +- .../-state/-s-u-s-p-e-n-d-e-d/index.html | 59 +- .../-state/index.html | 107 +- .../kotlinx.coroutines.debug/index.html | 121 +- kotlinx-coroutines-debug/navigation.html | 2047 ----------------- kotlinx-coroutines-guava/index.html | 71 +- .../kotlinx.coroutines.guava/as-deferred.html | 55 +- .../as-listenable-future.html | 55 +- .../kotlinx.coroutines.guava/await.html | 55 +- .../kotlinx.coroutines.guava/future.html | 55 +- .../kotlinx.coroutines.guava/index.html | 121 +- kotlinx-coroutines-guava/navigation.html | 2047 ----------------- kotlinx-coroutines-javafx/index.html | 73 +- .../-java-fx-dispatcher/index.html | 59 +- .../kotlinx.coroutines.javafx/-java-fx.html | 55 +- .../kotlinx.coroutines.javafx/as-flow.html | 55 +- .../await-pulse.html | 55 +- .../kotlinx.coroutines.javafx/index.html | 126 +- kotlinx-coroutines-javafx/navigation.html | 2047 ----------------- kotlinx-coroutines-jdk8/index.html | 101 +- .../as-completable-future.html | 55 +- .../as-deferred.html | 55 +- .../kotlinx.coroutines.future/await.html | 55 +- .../kotlinx.coroutines.future/future.html | 55 +- .../kotlinx.coroutines.future/index.html | 122 +- .../consume-as-flow.html | 55 +- .../kotlinx.coroutines.stream/index.html | 76 +- .../kotlinx.coroutines.time/debounce.html | 55 +- .../kotlinx.coroutines.time/delay.html | 55 +- .../kotlinx.coroutines.time/index.html | 151 +- .../kotlinx.coroutines.time/on-timeout.html | 55 +- .../kotlinx.coroutines.time/sample.html | 55 +- .../with-timeout-or-null.html | 55 +- .../kotlinx.coroutines.time/with-timeout.html | 55 +- kotlinx-coroutines-jdk8/navigation.html | 2047 ----------------- kotlinx-coroutines-jdk9/index.html | 73 +- .../kotlinx.coroutines.jdk9/as-flow.html | 55 +- .../kotlinx.coroutines.jdk9/as-publisher.html | 55 +- .../await-first-or-default.html | 55 +- .../await-first-or-else.html | 55 +- .../await-first-or-null.html | 55 +- .../kotlinx.coroutines.jdk9/await-first.html | 55 +- .../kotlinx.coroutines.jdk9/await-last.html | 55 +- .../kotlinx.coroutines.jdk9/await-single.html | 55 +- .../kotlinx.coroutines.jdk9/collect.html | 55 +- .../kotlinx.coroutines.jdk9/flow-publish.html | 55 +- .../kotlinx.coroutines.jdk9/index.html | 212 +- kotlinx-coroutines-jdk9/navigation.html | 2047 ----------------- kotlinx-coroutines-play-services/index.html | 71 +- .../kotlinx.coroutines.tasks/as-deferred.html | 55 +- .../kotlinx.coroutines.tasks/as-task.html | 55 +- .../kotlinx.coroutines.tasks/await.html | 55 +- .../kotlinx.coroutines.tasks/index.html | 106 +- .../navigation.html | 2047 ----------------- kotlinx-coroutines-reactive/index.html | 73 +- .../kotlinx.coroutines.reactive/as-flow.html | 55 +- .../as-publisher.html | 55 +- .../await-first-or-default.html | 55 +- .../await-first-or-else.html | 55 +- .../await-first-or-null.html | 55 +- .../await-first.html | 55 +- .../await-last.html | 55 +- .../await-single.html | 55 +- .../kotlinx.coroutines.reactive/collect.html | 55 +- .../kotlinx.coroutines.reactive/index.html | 212 +- .../kotlinx.coroutines.reactive/publish.html | 55 +- kotlinx-coroutines-reactive/navigation.html | 2047 ----------------- kotlinx-coroutines-reactor/index.html | 73 +- .../-reactor-context/-key/index.html | 59 +- .../-reactor-context/-reactor-context.html | 55 +- .../-reactor-context/context.html | 55 +- .../-reactor-context/index.html | 143 +- .../-reactor-context/to-string.html | 55 +- .../-scheduler-coroutine-dispatcher.html | 55 +- .../index.html | 98 +- .../scheduler.html | 55 +- .../as-coroutine-context.html | 55 +- .../as-coroutine-dispatcher.html | 55 +- .../kotlinx.coroutines.reactor/as-flux.html | 55 +- .../kotlinx.coroutines.reactor/as-mono.html | 55 +- .../await-single-or-null.html | 55 +- .../await-single.html | 55 +- .../kotlinx.coroutines.reactor/flux.html | 55 +- .../kotlinx.coroutines.reactor/index.html | 214 +- .../kotlinx.coroutines.reactor/mono.html | 55 +- kotlinx-coroutines-reactor/navigation.html | 2047 ----------------- kotlinx-coroutines-rx2/index.html | 73 +- .../-scheduler-coroutine-dispatcher.html | 55 +- .../index.html | 94 +- .../scheduler.html | 55 +- .../as-completable.html | 55 +- .../as-coroutine-dispatcher.html | 55 +- .../as-coroutine-dispatcher0.html | 55 +- .../kotlinx.coroutines.rx2/as-flow.html | 55 +- .../kotlinx.coroutines.rx2/as-flowable.html | 55 +- .../kotlinx.coroutines.rx2/as-maybe.html | 55 +- .../kotlinx.coroutines.rx2/as-observable.html | 55 +- .../kotlinx.coroutines.rx2/as-scheduler.html | 55 +- .../kotlinx.coroutines.rx2/as-single.html | 55 +- .../await-first-or-default.html | 55 +- .../await-first-or-else.html | 55 +- .../await-first-or-null.html | 55 +- .../kotlinx.coroutines.rx2/await-first.html | 55 +- .../kotlinx.coroutines.rx2/await-last.html | 55 +- .../await-single-or-null.html | 55 +- .../kotlinx.coroutines.rx2/await-single.html | 55 +- .../kotlinx.coroutines.rx2/await.html | 55 +- .../kotlinx.coroutines.rx2/collect.html | 55 +- .../kotlinx.coroutines.rx2/index.html | 424 +--- .../rx-completable.html | 55 +- .../kotlinx.coroutines.rx2/rx-flowable.html | 55 +- .../kotlinx.coroutines.rx2/rx-maybe.html | 55 +- .../kotlinx.coroutines.rx2/rx-observable.html | 55 +- .../kotlinx.coroutines.rx2/rx-single.html | 55 +- kotlinx-coroutines-rx2/navigation.html | 2047 ----------------- kotlinx-coroutines-rx3/index.html | 73 +- .../-scheduler-coroutine-dispatcher.html | 55 +- .../index.html | 94 +- .../scheduler.html | 55 +- .../as-completable.html | 55 +- .../as-coroutine-dispatcher.html | 55 +- .../as-coroutine-dispatcher0.html | 55 +- .../kotlinx.coroutines.rx3/as-flow.html | 55 +- .../kotlinx.coroutines.rx3/as-flowable.html | 55 +- .../kotlinx.coroutines.rx3/as-maybe.html | 55 +- .../kotlinx.coroutines.rx3/as-observable.html | 55 +- .../kotlinx.coroutines.rx3/as-scheduler.html | 55 +- .../kotlinx.coroutines.rx3/as-single.html | 55 +- .../await-first-or-default.html | 55 +- .../await-first-or-else.html | 55 +- .../await-first-or-null.html | 55 +- .../kotlinx.coroutines.rx3/await-first.html | 55 +- .../kotlinx.coroutines.rx3/await-last.html | 55 +- .../await-single-or-null.html | 55 +- .../kotlinx.coroutines.rx3/await-single.html | 55 +- .../kotlinx.coroutines.rx3/await.html | 55 +- .../kotlinx.coroutines.rx3/collect.html | 55 +- .../kotlinx.coroutines.rx3/index.html | 424 +--- .../rx-completable.html | 55 +- .../kotlinx.coroutines.rx3/rx-flowable.html | 55 +- .../kotlinx.coroutines.rx3/rx-maybe.html | 55 +- .../kotlinx.coroutines.rx3/rx-observable.html | 55 +- .../kotlinx.coroutines.rx3/rx-single.html | 55 +- kotlinx-coroutines-rx3/navigation.html | 2047 ----------------- kotlinx-coroutines-slf4j/index.html | 73 +- .../-m-d-c-context/-key/index.html | 59 +- .../-m-d-c-context/-m-d-c-context.html | 55 +- .../-m-d-c-context/context-map.html | 55 +- .../-m-d-c-context/index.html | 115 +- .../kotlinx.coroutines.slf4j/index.html | 92 +- kotlinx-coroutines-slf4j/navigation.html | 2047 ----------------- kotlinx-coroutines-swing/index.html | 73 +- .../-swing-dispatcher/index.html | 59 +- .../kotlinx.coroutines.swing/-swing.html | 55 +- .../kotlinx.coroutines.swing/index.html | 94 +- kotlinx-coroutines-swing/navigation.html | 2047 ----------------- kotlinx-coroutines-test/index.html | 86 +- .../-delay-controller/advance-time-by.html | 60 +- .../-delay-controller/advance-until-idle.html | 60 +- .../cleanup-test-coroutines.html | 60 +- .../-delay-controller/current-time.html | 60 +- .../-delay-controller/index.html | 188 +- .../-delay-controller/pause-dispatcher.html | 60 +- .../-delay-controller/resume-dispatcher.html | 60 +- .../-delay-controller/run-current.html | 60 +- .../-standard-test-dispatcher.html | 60 +- .../-test-coroutine-dispatcher.html | 60 +- .../-test-coroutine-dispatcher/index.html | 128 +- .../-test-coroutine-dispatcher/scheduler.html | 60 +- .../-test-coroutine-exception-handler.html | 60 +- .../cleanup-test-coroutines.html | 60 +- .../handle-exception.html | 60 +- .../index.html | 139 +- .../uncaught-exceptions.html | 60 +- .../-test-coroutine-scheduler.html | 60 +- .../advance-time-by.html | 60 +- .../advance-until-idle.html | 60 +- .../current-time.html | 60 +- .../-test-coroutine-scheduler/index.html | 173 +- .../run-current.html | 60 +- .../time-source.html | 60 +- .../-test-coroutine-scope.html | 60 +- .../cleanup-test-coroutines.html | 60 +- .../-test-coroutine-scope/index.html | 258 +-- .../-test-coroutine-scope/test-scheduler.html | 60 +- .../-test-dispatcher/index.html | 98 +- .../-test-dispatcher/scheduler.html | 60 +- .../-test-result/index.html | 67 +- .../kotlinx.coroutines.test/-test-scope.html | 60 +- .../-test-scope/index.html | 206 +- .../-test-scope/test-scheduler.html | 60 +- .../cleanup-test-coroutines.html | 60 +- .../-uncaught-exception-captor/index.html | 116 +- .../uncaught-exceptions.html | 60 +- .../-unconfined-test-dispatcher.html | 60 +- .../advance-time-by.html | 61 +- .../advance-until-idle.html | 61 +- .../create-test-coroutine-scope.html | 60 +- .../kotlinx.coroutines.test/current-time.html | 61 +- .../kotlinx.coroutines.test/index.html | 547 +---- .../pause-dispatcher.html | 60 +- .../kotlinx.coroutines.test/reset-main.html | 60 +- .../resume-dispatcher.html | 60 +- .../run-blocking-test-on-test-scope.html | 60 +- .../run-blocking-test.html | 60 +- .../kotlinx.coroutines.test/run-current.html | 61 +- .../run-test-with-legacy-scope.html | 60 +- .../kotlinx.coroutines.test/run-test.html | 61 +- .../kotlinx.coroutines.test/set-main.html | 60 +- .../test-time-source.html | 60 +- .../uncaught-exceptions.html | 60 +- kotlinx-coroutines-test/navigation.html | 2047 ----------------- navigation.html | 2047 ----------------- 642 files changed, 626 insertions(+), 88311 deletions(-) create mode 100644 README.md delete mode 100644 kotlinx-coroutines-android/navigation.html delete mode 100644 kotlinx-coroutines-core/navigation.html delete mode 100644 kotlinx-coroutines-debug/navigation.html delete mode 100644 kotlinx-coroutines-guava/navigation.html delete mode 100644 kotlinx-coroutines-javafx/navigation.html delete mode 100644 kotlinx-coroutines-jdk8/navigation.html delete mode 100644 kotlinx-coroutines-jdk9/navigation.html delete mode 100644 kotlinx-coroutines-play-services/navigation.html delete mode 100644 kotlinx-coroutines-reactive/navigation.html delete mode 100644 kotlinx-coroutines-reactor/navigation.html delete mode 100644 kotlinx-coroutines-rx2/navigation.html delete mode 100644 kotlinx-coroutines-rx3/navigation.html delete mode 100644 kotlinx-coroutines-slf4j/navigation.html delete mode 100644 kotlinx-coroutines-swing/navigation.html delete mode 100644 kotlinx-coroutines-test/navigation.html delete mode 100644 navigation.html diff --git a/README.md b/README.md new file mode 100644 index 0000000000..bc5d6a2805 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Pages moved to [kotlinlang.org](https://kotlinlang.org/api/kotlinx.coroutines/) diff --git a/index.html b/index.html index ec2bbcd559..58947e8767 100644 --- a/index.html +++ b/index.html @@ -1,254 +1 @@ - - - - - All modules - - - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

All modules:

-
-
-
-
- - -
Link copied to clipboard
-
-
-

Provides Dispatchers.Main context for Android applications.

-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-

Core primitives to work with coroutines.

-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-

Debugging facilities for kotlinx.coroutines on JVM.

-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-

Integration with Guava ListenableFuture.

-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-

Provides Dispatchers.JavaFx context and Dispatchers.Main implementation for JavaFX UI applications.

-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-

Integration with JDK8 CompletableFuture (Android API level 24).

-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-

Utilities for Java Flow.

-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-

Integration with Google Play Services Tasks API.

-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-

Utilities for Reactive Streams.

-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-

Utilities for Reactor.

-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-

Utilities for RxJava 2.x.

-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-

Utilities for RxJava 3.x.

-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-

Integration with SLF4J MDC.

-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-

Provides Dispatchers.Swing context and Dispatchers.Main implementation for Swing UI applications.

-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-

Test utilities for kotlinx.coroutines.

-
-
-
-
-
-
- -
-
- - + \ No newline at end of file diff --git a/kotlinx-coroutines-android/index.html b/kotlinx-coroutines-android/index.html index 77637fd5a9..6c06fd653b 100644 --- a/kotlinx-coroutines-android/index.html +++ b/kotlinx-coroutines-android/index.html @@ -1,72 +1 @@ - - - - - kotlinx-coroutines-android - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

kotlinx-coroutines-android

-

Provides Dispatchers.Main context for Android applications.

Read Guide to UI programming with coroutines for tutorial on this module.

Optimization

R8 and ProGuard rules are bundled into this module. R8 is a replacement for ProGuard in Android ecosystem, it is enabled by default since Android gradle plugin 3.4.0 (3.3.0-beta also had it enabled). For best results it is recommended to use a recent version of R8, which produces a smaller binary.

When optimizations are enabled with R8 version 1.6.0 or later the following debugging features are permanently turned off to reduce the size of the resulting binary:

  • ../../docs/debugging.md#debug-mode

  • ../../docs/debugging.md#stacktrace-recovery

  • The internal assertions in the library are also permanently removed.

You can examine the corresponding rules in this resources/META-INF/com.android.tools/r8-from-1.6.0/coroutines.pro file.

-
-

Packages

-
-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-

Provides Dispatchers.Main context for Android applications.

-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-android/kotlinx.coroutines.android/-handler-dispatcher/immediate.html b/kotlinx-coroutines-android/kotlinx.coroutines.android/-handler-dispatcher/immediate.html index 72398ef0b9..60a36d1642 100644 --- a/kotlinx-coroutines-android/kotlinx.coroutines.android/-handler-dispatcher/immediate.html +++ b/kotlinx-coroutines-android/kotlinx.coroutines.android/-handler-dispatcher/immediate.html @@ -1,54 +1 @@ - - - - - immediate - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

immediate

-
-
abstract override val immediate: HandlerDispatcher

Returns dispatcher that executes coroutines immediately when it is already in the right context (current looper is the same as this handler's looper) without an additional re-dispatch. This dispatcher does not use Handler.post when current looper is the same as looper of the handler.

Immediate dispatcher is safe from stack overflows and in case of nested invocations forms event-loop similar to Dispatchers.Unconfined. The event loop is an advanced topic and its implications can be found in Dispatchers.Unconfined documentation.

Example of usage:

suspend fun updateUiElement(val text: String) {
/*
* If it is known that updateUiElement can be invoked both from the Main thread and from other threads,
* `immediate` dispatcher is used as a performance optimization to avoid unnecessary dispatch.
*
* In that case, when `updateUiElement` is invoked from the Main thread, `uiElement.text` will be
* invoked immediately without any dispatching, otherwise, the `Dispatchers.Main` dispatch cycle via
* `Handler.post` will be triggered.
*/
withContext(Dispatchers.Main.immediate) {
uiElement.text = text
}
// Do context-independent logic such as logging
}
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-android/kotlinx.coroutines.android/-handler-dispatcher/index.html b/kotlinx-coroutines-android/kotlinx.coroutines.android/-handler-dispatcher/index.html index f65584e8a3..c43f79771e 100644 --- a/kotlinx-coroutines-android/kotlinx.coroutines.android/-handler-dispatcher/index.html +++ b/kotlinx-coroutines-android/kotlinx.coroutines.android/-handler-dispatcher/index.html @@ -1,76 +1 @@ - - - - - HandlerDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

HandlerDispatcher

-
sealed class HandlerDispatcher : MainCoroutineDispatcher, Delay

Dispatches execution onto Android Handler.

This class provides type-safety and a point for future extensions.

-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
abstract override val immediate: HandlerDispatcher

Returns dispatcher that executes coroutines immediately when it is already in the right context (current looper is the same as this handler's looper) without an additional re-dispatch. This dispatcher does not use Handler.post when current looper is the same as looper of the handler.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-android/kotlinx.coroutines.android/as-coroutine-dispatcher.html b/kotlinx-coroutines-android/kotlinx.coroutines.android/as-coroutine-dispatcher.html index 610ace3d89..0e157261f3 100644 --- a/kotlinx-coroutines-android/kotlinx.coroutines.android/as-coroutine-dispatcher.html +++ b/kotlinx-coroutines-android/kotlinx.coroutines.android/as-coroutine-dispatcher.html @@ -1,54 +1 @@ - - - - - asCoroutineDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asCoroutineDispatcher

-
-
@JvmName(name = "from")
fun Handler.asCoroutineDispatcher(name: String? = null): HandlerDispatcher

Represents an arbitrary Handler as an implementation of CoroutineDispatcher with an optional name for nicer debugging

Rejected execution

If the underlying handler is closed and its message-scheduling methods start to return false on an attempt to submit a continuation task to the resulting dispatcher, then the Job of the affected task is cancelled and the task is submitted to the Dispatchers.IO, so that the affected coroutine can cleanup its resources and promptly complete.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-android/kotlinx.coroutines.android/await-frame.html b/kotlinx-coroutines-android/kotlinx.coroutines.android/await-frame.html index 199628d1b1..d5771edf26 100644 --- a/kotlinx-coroutines-android/kotlinx.coroutines.android/await-frame.html +++ b/kotlinx-coroutines-android/kotlinx.coroutines.android/await-frame.html @@ -1,54 +1 @@ - - - - - awaitFrame - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitFrame

-
-
suspend fun awaitFrame(): Long

Awaits the next animation frame and returns frame time in nanoseconds.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-android/kotlinx.coroutines.android/index.html b/kotlinx-coroutines-android/kotlinx.coroutines.android/index.html index ad14f7603d..c7b81cc753 100644 --- a/kotlinx-coroutines-android/kotlinx.coroutines.android/index.html +++ b/kotlinx-coroutines-android/kotlinx.coroutines.android/index.html @@ -1,108 +1 @@ - - - - - kotlinx.coroutines.android - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Package kotlinx.coroutines.android

-

Provides Dispatchers.Main context for Android applications.

-
-
-
-
-

Types

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
sealed class HandlerDispatcher : MainCoroutineDispatcher, Delay

Dispatches execution onto Android Handler.

-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
@JvmName(name = "from")
fun Handler.asCoroutineDispatcher(name: String? = null): HandlerDispatcher

Represents an arbitrary Handler as an implementation of CoroutineDispatcher with an optional name for nicer debugging

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun awaitFrame(): Long

Awaits the next animation frame and returns frame time in nanoseconds.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-android/navigation.html b/kotlinx-coroutines-android/navigation.html deleted file mode 100644 index be03fe14df..0000000000 --- a/kotlinx-coroutines-android/navigation.html +++ /dev/null @@ -1,2047 +0,0 @@ -
- -
- -
- - - -
- -
-
- -
-
- -
-
-
- async() -
-
-
-
- await() -
-
-
- -
- - -
-
- cancel() -
-
-
- -
- - - - - - - - -
- -
-
- -
- - - - - -
- -
-
- -
- - -
- -
-
- ATOMIC -
-
-
-
- DEFAULT -
-
-
-
- LAZY -
-
-
- -
-
- - - - - -
-
- Deferred -
-
-
-
- delay() -
-
- -
- -
- -
- -
-
- -
- - -
- -
-
- -
- - -
-
- invoke() -
-
- -
-
- isActive -
-
-
- -
-
-
- Job -
-
-
-
- job -
-
-
-
- Job() -
-
-
-
- joinAll() -
-
-
-
- launch() -
-
- -
- -
- - - -
- -
- -
-
- plus() -
-
-
-
- promise() -
-
-
- -
- -
-
- Runnable -
-
-
- -
-
- -
- - - - -
- -
-
- -
- -
-
- yield() -
-
-
-
- -
-
- actor() -
-
-
- -
-
- -
-
- -
- - -
- -
- -
-
- -
-
-
- SUSPEND -
-
-
-
-
- Channel -
-
-
-
- Channel() -
-
-
- -
-
- -
- - - -
-
- consume() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- produce() -
-
-
- -
-
- -
-
- -
-
-
- ticker() -
-
-
- -
- -
-
- -
-
-
-
- toList() -
-
- -
-
- -
- -
-
-
- asFlow() -
-
-
- -
-
- -
-
-
- buffer() -
-
-
- -
-
- -
-
-
- catch() -
-
-
- -
-
-
- collect() -
-
- -
- -
-
-
- combine() -
-
- -
- -
-
- -
-
-
- count() -
-
-
- -
- - - - -
-
- drop() -
-
-
- -
-
-
- emitAll() -
-
-
- -
-
-
- filter() -
-
- -
- -
-
- -
-
-
- first() -
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
- Flow -
-
-
-
- flow() -
-
-
- -
-
-
- flowOf() -
-
-
-
- flowOn() -
-
-
-
- fold() -
-
-
- -
-
-
- last() -
-
-
- -
-
- -
-
-
- map() -
-
-
- -
-
- -
-
-
- merge() -
-
- - - - -
- -
-
-
- onEach() -
-
-
-
- onEmpty() -
-
-
-
- onStart() -
-
- -
- -
-
- -
-
-
- reduce() -
-
-
-
- retry() -
-
-
- -
-
- -
-
- -
-
-
- sample() -
-
-
-
- scan() -
-
-
- -
-
-
- shareIn() -
-
-
- -
-
- START -
-
-
-
- STOP -
-
- -
-
- -
-
-
- single() -
-
-
- -
-
-
- StateFlow -
-
-
-
- stateIn() -
-
-
-
- take() -
-
-
- -
-
- -
-
-
- toList() -
-
-
-
- toSet() -
-
-
- -
- - -
-
- update() -
-
-
- -
- -
- -
-
-
- zip() -
-
-
- -
- -
- -
-
-
- select() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- -
-
- Mutex -
-
-
-
- Mutex() -
-
-
-
- Semaphore -
-
-
- -
-
- -
-
- -
-
-
- -
- -
- -
- -
- -
-
- await() -
-
-
-
- future() -
-
-
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
-
- JavaFx -
-
- -
-
-
- -
- - -
- -
-
-
- await() -
-
-
-
- future() -
-
-
- -
- -
- -
-
-
- delay() -
-
-
- -
-
-
- sample() -
-
-
- -
- -
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
- -
-
-
- -
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
-
- publish() -
-
-
-
- -
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
-
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
- - - -
diff --git a/kotlinx-coroutines-core/index.html b/kotlinx-coroutines-core/index.html index eb5a9192d4..8d5a0934b5 100644 --- a/kotlinx-coroutines-core/index.html +++ b/kotlinx-coroutines-core/index.html @@ -1,191 +1 @@ - - - - - kotlinx-coroutines-core - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

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).

-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-actor-scope/channel.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-actor-scope/channel.html index 235d14c458..ed0ccf07c0 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-actor-scope/channel.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-actor-scope/channel.html @@ -1,72 +1 @@ - - - - - channel - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

channel

-
-
-
-
abstract val channel: Channel<E>

A reference to the mailbox channel that this coroutine receives messages from. It is provided for convenience, so that the code in the coroutine can refer to the channel as channel as apposed to this. All the ReceiveChannel functions on this interface delegate to the channel instance returned by this function.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-actor-scope/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-actor-scope/index.html index 061e94e63e..42f4f7f0d1 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-actor-scope/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-actor-scope/index.html @@ -1,96 +1 @@ - - - - - ActorScope - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

ActorScope

-
-
-
interface ActorScope<E> : CoroutineScope, ReceiveChannel<E>

Scope for actor coroutine builder.

Note: This API will become obsolete in future updates with introduction of complex actors. See issue #87.

-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val channel: Channel<E>

A reference to the mailbox channel that this coroutine receives messages from. It is provided for convenience, so that the code in the coroutine can refer to the channel as channel as apposed to this. All the ReceiveChannel functions on this interface delegate to the channel instance returned by this function.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-broadcast-channel.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-broadcast-channel.html index 8a04431f6d..d270d26ffe 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-broadcast-channel.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-broadcast-channel.html @@ -1,72 +1 @@ - - - - - BroadcastChannel - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

BroadcastChannel

-
-
-
-
fun <E> BroadcastChannel(capacity: Int): BroadcastChannel<E>

Creates a broadcast channel with the specified buffer capacity.

The resulting channel type depends on the specified capacity parameter:

  • when capacity positive, but less than UNLIMITED -- creates ArrayBroadcastChannel with a buffer of given capacity. Note: this channel looses all items that are send to it until the first subscriber appears;

  • when capacity is CONFLATED -- creates ConflatedBroadcastChannel that conflates back-to-back sends;

  • when capacity is BUFFERED -- creates ArrayBroadcastChannel with a default capacity.

  • otherwise -- throws IllegalArgumentException.

Note: This API is obsolete since 1.5.0. It will be deprecated with warning in 1.6.0 and with error in 1.7.0. It is replaced with StateFlow and SharedFlow.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-broadcast-channel/cancel.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-broadcast-channel/cancel.html index e49401cf0b..f8795fdc6b 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-broadcast-channel/cancel.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-broadcast-channel/cancel.html @@ -1,72 +1 @@ - - - - - cancel - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

cancel

-
-
-
-
abstract fun cancel(cause: CancellationException? = null)

Cancels reception of remaining elements from this channel with an optional cause. This function closes the channel with the specified cause (unless it was already closed), removes all buffered sent elements from it, and cancels all open subscriptions. A cause can be used to specify an error message or to provide other details on a cancellation reason for debugging purposes.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-broadcast-channel/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-broadcast-channel/index.html index 0c6ced9e0c..554fcca3ff 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-broadcast-channel/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-broadcast-channel/index.html @@ -1,179 +1 @@ - - - - - BroadcastChannel - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

BroadcastChannel

-
-
-
interface BroadcastChannel<E> : SendChannel<E>

Broadcast channel is a non-blocking primitive for communication between the sender and multiple receivers that subscribe for the elements using openSubscription function and unsubscribe using ReceiveChannel.cancel function.

See BroadcastChannel() factory function for the description of available broadcast channel implementations.

Note: This API is obsolete since 1.5.0. It will be deprecated with warning in 1.6.0 and with error in 1.7.0. It is replaced with SharedFlow.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun cancel(cause: CancellationException? = null)

Cancels reception of remaining elements from this channel with an optional cause. This function closes the channel with the specified cause (unless it was already closed), removes all buffered sent elements from it, and cancels all open subscriptions. A cause can be used to specify an error message or to provide other details on a cancellation reason for debugging purposes.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun openSubscription(): ReceiveChannel<E>

Subscribes to this BroadcastChannel and returns a channel to receive elements from it. The resulting channel shall be cancelled to unsubscribe from this broadcast channel.

-
-
-
-
-
-

Inheritors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Extensions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> BroadcastChannel<T>.asFlow(): Flow<T>

Represents the given broadcast channel as a hot flow. Every flow collector will trigger a new broadcast channel subscription.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <E, R> BroadcastChannel<E>.consume(block: ReceiveChannel<E>.() -> R): R

Opens subscription to this BroadcastChannel and makes sure that the given block consumes all elements from it by always invoking cancel after the execution of the block.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline suspend fun <E> BroadcastChannel<E>.consumeEach(action: (E) -> Unit)

Subscribes to this BroadcastChannel and performs the specified action for each received element.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-broadcast-channel/open-subscription.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-broadcast-channel/open-subscription.html index 29a7ebd39b..c77c0d2943 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-broadcast-channel/open-subscription.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-broadcast-channel/open-subscription.html @@ -1,72 +1 @@ - - - - - openSubscription - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

openSubscription

-
-
-
-
abstract fun openSubscription(): ReceiveChannel<E>

Subscribes to this BroadcastChannel and returns a channel to receive elements from it. The resulting channel shall be cancelled to unsubscribe from this broadcast channel.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-buffer-overflow/-d-r-o-p_-l-a-t-e-s-t/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-buffer-overflow/-d-r-o-p_-l-a-t-e-s-t/index.html index 381db936dc..1ef35f2eab 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-buffer-overflow/-d-r-o-p_-l-a-t-e-s-t/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-buffer-overflow/-d-r-o-p_-l-a-t-e-s-t/index.html @@ -1,63 +1 @@ - - - - - DROP_LATEST - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

DROP_LATEST

-
-
-

Drop the latest value that is being added to the buffer right now on buffer overflow (so that buffer contents stay the same), do not suspend.

-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-buffer-overflow/-d-r-o-p_-o-l-d-e-s-t/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-buffer-overflow/-d-r-o-p_-o-l-d-e-s-t/index.html index d0ed63245f..5256b9cf7a 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-buffer-overflow/-d-r-o-p_-o-l-d-e-s-t/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-buffer-overflow/-d-r-o-p_-o-l-d-e-s-t/index.html @@ -1,63 +1 @@ - - - - - DROP_OLDEST - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

DROP_OLDEST

-
-
-

Drop the oldest value in the buffer on overflow, add the new value to the buffer, do not suspend.

-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-buffer-overflow/-s-u-s-p-e-n-d/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-buffer-overflow/-s-u-s-p-e-n-d/index.html index 2012d0c81f..a346ce1047 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-buffer-overflow/-s-u-s-p-e-n-d/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-buffer-overflow/-s-u-s-p-e-n-d/index.html @@ -1,63 +1 @@ - - - - - SUSPEND - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

SUSPEND

-
-
-

Suspend on buffer overflow.

-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-buffer-overflow/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-buffer-overflow/index.html index f484b1bb77..21d221ebe9 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-buffer-overflow/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-buffer-overflow/index.html @@ -1,130 +1 @@ - - - - - BufferOverflow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

BufferOverflow

-
-
-
enum BufferOverflow : Enum<BufferOverflow>

A strategy for buffer overflow handling in channels and flows that controls what is going to be sacrificed on buffer overflow:

  • SUSPEND — the upstream that is sending or is emitting a value is suspended while the buffer is full.

  • DROP_OLDEST — drop the oldest value in the buffer on overflow, add the new value to the buffer, do not suspend.

  • DROP_LATEST — drop the latest value that is being added to the buffer right now on buffer overflow (so that buffer contents stay the same), do not suspend.

-
-
-
-
-

Entries

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Drop the latest value that is being added to the buffer right now on buffer overflow (so that buffer contents stay the same), do not suspend.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Drop the oldest value in the buffer on overflow, add the new value to the buffer, do not suspend.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Suspend on buffer overflow.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-iterator/has-next.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-iterator/has-next.html index 85e8f5cbf0..3b02818ddc 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-iterator/has-next.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-iterator/has-next.html @@ -1,72 +1 @@ - - - - - hasNext - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

hasNext

-
-
-
-
abstract suspend operator fun hasNext(): Boolean

Returns true if the channel has more elements, suspending the caller while this channel is empty, or returns false if the channel is closed for receive without a cause. It throws the original close cause exception if the channel has failed.

This function retrieves and removes an element from this channel for the subsequent invocation of next.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this function is suspended, this function immediately resumes with a CancellationException. There is a prompt cancellation guarantee. If the job was cancelled while this function was suspended, it will not resume successfully. The hasNext call can retrieve the element from the channel, but then throw CancellationException, thus failing to deliver the element. See "Undelivered elements" section in Channel documentation for details on handling undelivered elements.

Note that this function does not check for cancellation when it is not suspended. Use yield or CoroutineScope.isActive to periodically check for cancellation in tight loops if needed.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-iterator/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-iterator/index.html index ac01fcd790..5fc30b7e06 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-iterator/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-iterator/index.html @@ -1,130 +1 @@ - - - - - ChannelIterator - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

ChannelIterator

-
-
-
interface ChannelIterator<out E>

Iterator for ReceiveChannel. Instances of this interface are not thread-safe and shall not be used from concurrent coroutines.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract suspend operator fun hasNext(): Boolean

Returns true if the channel has more elements, suspending the caller while this channel is empty, or returns false if the channel is closed for receive without a cause. It throws the original close cause exception if the channel has failed.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract operator fun next(): E

Retrieves the element removed from the channel by a preceding call to hasNext, or throws an IllegalStateException if hasNext was not invoked. This method should only be used in pair with hasNext:

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
@JvmName(name = "next")
open suspend fun next0(): E
-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-iterator/next.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-iterator/next.html index 2050bbf25d..9d9fd43f88 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-iterator/next.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-iterator/next.html @@ -1,72 +1 @@ - - - - - next - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

next

-
-
-
-
abstract operator fun next(): E

Retrieves the element removed from the channel by a preceding call to hasNext, or throws an IllegalStateException if hasNext was not invoked. This method should only be used in pair with hasNext:

while (iterator.hasNext()) {
val element = iterator.next()
// ... handle element ...
}

This method throws a ClosedReceiveChannelException if the channel is closed for receive without a cause. It throws the original close cause exception if the channel has failed.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-iterator/next0.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-iterator/next0.html index a57f01d26d..f66c6a6b4d 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-iterator/next0.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-iterator/next0.html @@ -1,72 +1 @@ - - - - - next0 - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

next0

-
-
-
-
@JvmName(name = "next")
open suspend fun next0(): E
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/-companion/closed.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/-companion/closed.html index d934d5aa31..dda0a9d119 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/-companion/closed.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/-companion/closed.html @@ -1,72 +1 @@ - - - - - closed - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

closed

-
-
-
-
fun <E> closed(cause: Throwable?): ChannelResult<E>
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/-companion/failure.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/-companion/failure.html index 7236a17ae4..d4f8bda71b 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/-companion/failure.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/-companion/failure.html @@ -1,72 +1 @@ - - - - - failure - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

failure

-
-
-
-
fun <E> failure(): ChannelResult<E>
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/-companion/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/-companion/index.html index 1edf39e2c5..4f8716b21b 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/-companion/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/-companion/index.html @@ -1,130 +1 @@ - - - - - Companion - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Companion

-
-
-
object Companion
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <E> closed(cause: Throwable?): ChannelResult<E>
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <E> failure(): ChannelResult<E>
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <E> success(value: E): ChannelResult<E>
-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/-companion/success.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/-companion/success.html index dda5294095..8c0a538450 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/-companion/success.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/-companion/success.html @@ -1,72 +1 @@ - - - - - success - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

success

-
-
-
-
fun <E> success(value: E): ChannelResult<E>
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/exception-or-null.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/exception-or-null.html index 83c38c1c3d..70fc3fba59 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/exception-or-null.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/exception-or-null.html @@ -1,72 +1 @@ - - - - - exceptionOrNull - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

exceptionOrNull

-
-
-
-
fun exceptionOrNull(): Throwable?

Returns the encapsulated exception if this instance represents failure or null if it is success or unsuccessful operation to closed channel.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/get-or-null.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/get-or-null.html index 0dfb9e0c22..97cd1a76ce 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/get-or-null.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/get-or-null.html @@ -1,72 +1 @@ - - - - - getOrNull - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

getOrNull

-
-
-
-
fun getOrNull(): T?

Returns the encapsulated value if this instance represents success or null if it represents failed result.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/get-or-throw.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/get-or-throw.html index cf2cbd420b..8de4aea3f3 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/get-or-throw.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/get-or-throw.html @@ -1,72 +1 @@ - - - - - getOrThrow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

getOrThrow

-
-
-
-
fun getOrThrow(): T

Returns the encapsulated value if this instance represents success or throws an exception if it is closed or failed.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/index.html index 6d311044b7..18dc178f5e 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/index.html @@ -1,289 +1 @@ - - - - - ChannelResult - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

ChannelResult

-
-
-
value class ChannelResult<out T>

A discriminated union of channel operation result. It encapsulates the successful or failed result of a channel operation or a failed operation to a closed channel with an optional cause.

The successful result represents a successful operation with a value of type T, for example, the result of Channel.receiveCatching operation or a successfully sent element as a result of Channel.trySend.

The failed result represents a failed operation attempt to a channel, but it doesn't necessary indicate that the channel is failed. E.g. when the channel is full, Channel.trySend returns failed result, but the channel itself is not in the failed state.

The closed result represents an operation attempt to a closed channel and also implies that the operation has failed. It is guaranteed that if the result is closed, then the target channel is either closed for send or is closed for receive depending on whether the failed operation was sending or receiving.

-
-
-
-
-

Types

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
object Companion
-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun exceptionOrNull(): Throwable?

Returns the encapsulated exception if this instance represents failure or null if it is success or unsuccessful operation to closed channel.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun getOrNull(): T?

Returns the encapsulated value if this instance represents success or null if it represents failed result.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun getOrThrow(): T

Returns the encapsulated value if this instance represents success or throws an exception if it is closed or failed.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
open override fun toString(): String
-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
val isClosed: Boolean

Returns true if this instance represents unsuccessful operation to a closed or cancelled channel.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
val isFailure: Boolean

Returns true if this instance represents unsuccessful operation.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
val isSuccess: Boolean

Returns true if this instance represents a successful operation outcome.

-
-
-
-
-
-

Extensions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T> ChannelResult<T>.getOrElse(onFailure: (exception: Throwable?) -> T): T

Returns the encapsulated value if this instance represents success or the result of onFailure function for the encapsulated Throwable exception if it is failed or closed result.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T> ChannelResult<T>.onClosed(action: (exception: Throwable?) -> Unit): ChannelResult<T>

Performs the given action on the encapsulated Throwable exception if this instance represents failure due to channel being closed. The result of ChannelResult.exceptionOrNull is passed to the action parameter. It is guaranteed that if action is invoked, then the channel is either closed for send or is closed for receive depending on the failed operation.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T> ChannelResult<T>.onFailure(action: (exception: Throwable?) -> Unit): ChannelResult<T>

Performs the given action on the encapsulated Throwable exception if this instance represents failure. The result of ChannelResult.exceptionOrNull is passed to the action parameter.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T> ChannelResult<T>.onSuccess(action: (T) -> Unit): ChannelResult<T>

Performs the given action on the encapsulated value if this instance represents success. Returns the original ChannelResult unchanged.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/is-closed.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/is-closed.html index ccf4f00d48..e7b14860f6 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/is-closed.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/is-closed.html @@ -1,72 +1 @@ - - - - - isClosed - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

isClosed

-
-
-
-
val isClosed: Boolean

Returns true if this instance represents unsuccessful operation to a closed or cancelled channel.

In this case isSuccess returns false, isFailure returns true, but it does not imply that exceptionOrNull returns non-null value.

It can happen if the channel was closed normally without an exception.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/is-failure.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/is-failure.html index f8d5185d4f..5970bb5f35 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/is-failure.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/is-failure.html @@ -1,72 +1 @@ - - - - - isFailure - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

isFailure

-
-
-
-
val isFailure: Boolean

Returns true if this instance represents unsuccessful operation.

In this case isSuccess returns false, but it does not imply that the channel is failed or closed.

Example of a failed operation without an exception and channel being closed is Channel.trySend attempt to a channel that is full.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/is-success.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/is-success.html index b300ebb76a..30e4152707 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/is-success.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/is-success.html @@ -1,72 +1 @@ - - - - - isSuccess - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

isSuccess

-
-
-
-
val isSuccess: Boolean

Returns true if this instance represents a successful operation outcome.

In this case isFailure and isClosed return false.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/to-string.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/to-string.html index aedb5dea42..70f28c8647 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/to-string.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel-result/to-string.html @@ -1,72 +1 @@ - - - - - toString - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

toString

-
-
-
-
open override fun toString(): String
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel.html index aa8495e009..ce10d9ef2d 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel.html @@ -1,83 +1 @@ - - - - - Channel - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Channel

-
-
-
-
fun <E> Channel(    capacity: Int = RENDEZVOUS,     onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND,     onUndeliveredElement: (E) -> Unit? = null): Channel<E>

Creates a channel with the specified buffer capacity (or without a buffer by default). See Channel interface documentation for details.

Parameters

capacity

either a positive channel capacity or one of the constants defined in Channel.Factory.

onBufferOverflow

configures an action on buffer overflow (optional, defaults to a suspending attempt to send a value, supported only when capacity >= 0 or capacity == Channel.BUFFERED, implicitly creates a channel with at least one buffered element).

onUndeliveredElement

an optional function that is called when element was sent but was not delivered to the consumer. See "Undelivered elements" section in Channel documentation.

Throws


fun <E> Channel(capacity: Int = RENDEZVOUS): Channel<E>
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/-factory/-b-u-f-f-e-r-e-d.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/-factory/-b-u-f-f-e-r-e-d.html index d523f2003e..12ba1f68f9 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/-factory/-b-u-f-f-e-r-e-d.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/-factory/-b-u-f-f-e-r-e-d.html @@ -1,72 +1 @@ - - - - - BUFFERED - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

BUFFERED

-
-
-
-
const val BUFFERED: Int

Requests a buffered channel with the default buffer capacity in the Channel(...) factory function. The default capacity for a channel that suspends on overflow is 64 and can be overridden by setting DEFAULT_BUFFER_PROPERTY_NAME on JVM. For non-suspending channels, a buffer of capacity 1 is used.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/-factory/-c-o-n-f-l-a-t-e-d.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/-factory/-c-o-n-f-l-a-t-e-d.html index 70b38c0a76..20f5e31d8d 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/-factory/-c-o-n-f-l-a-t-e-d.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/-factory/-c-o-n-f-l-a-t-e-d.html @@ -1,72 +1 @@ - - - - - CONFLATED - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CONFLATED

-
-
-
-
const val CONFLATED: Int

Requests a conflated channel in the Channel(...) factory function. This is a shortcut to creating a channel with onBufferOverflow = DROP_OLDEST.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/-factory/-d-e-f-a-u-l-t_-b-u-f-f-e-r_-p-r-o-p-e-r-t-y_-n-a-m-e.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/-factory/-d-e-f-a-u-l-t_-b-u-f-f-e-r_-p-r-o-p-e-r-t-y_-n-a-m-e.html index edadd04e8f..9a42c8085d 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/-factory/-d-e-f-a-u-l-t_-b-u-f-f-e-r_-p-r-o-p-e-r-t-y_-n-a-m-e.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/-factory/-d-e-f-a-u-l-t_-b-u-f-f-e-r_-p-r-o-p-e-r-t-y_-n-a-m-e.html @@ -1,72 +1 @@ - - - - - DEFAULT_BUFFER_PROPERTY_NAME - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

DEFAULT_BUFFER_PROPERTY_NAME

-
-
-
-
const val DEFAULT_BUFFER_PROPERTY_NAME: String

Name of the property that defines the default channel capacity when BUFFERED is used as parameter in Channel(...) factory function.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/-factory/-r-e-n-d-e-z-v-o-u-s.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/-factory/-r-e-n-d-e-z-v-o-u-s.html index c5b3d44f74..18d8c40927 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/-factory/-r-e-n-d-e-z-v-o-u-s.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/-factory/-r-e-n-d-e-z-v-o-u-s.html @@ -1,72 +1 @@ - - - - - RENDEZVOUS - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

RENDEZVOUS

-
-
-
-
const val RENDEZVOUS: Int = 0

Requests a rendezvous channel in the Channel(...) factory function — a channel that does not have a buffer.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/-factory/-u-n-l-i-m-i-t-e-d.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/-factory/-u-n-l-i-m-i-t-e-d.html index 37d3423075..5b300b2ab0 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/-factory/-u-n-l-i-m-i-t-e-d.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/-factory/-u-n-l-i-m-i-t-e-d.html @@ -1,72 +1 @@ - - - - - UNLIMITED - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

UNLIMITED

-
-
-
-
const val UNLIMITED: Int

Requests a channel with an unlimited capacity buffer in the Channel(...) factory function.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/-factory/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/-factory/index.html index 811b0ce12a..7bcdff90dd 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/-factory/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/-factory/index.html @@ -1,164 +1 @@ - - - - - Factory - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Factory

-
-
-
object Factory

Constants for the channel factory function Channel().

-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
const val BUFFERED: Int

Requests a buffered channel with the default buffer capacity in the Channel(...) factory function. The default capacity for a channel that suspends on overflow is 64 and can be overridden by setting DEFAULT_BUFFER_PROPERTY_NAME on JVM. For non-suspending channels, a buffer of capacity 1 is used.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
const val CONFLATED: Int

Requests a conflated channel in the Channel(...) factory function. This is a shortcut to creating a channel with onBufferOverflow = DROP_OLDEST.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
const val DEFAULT_BUFFER_PROPERTY_NAME: String

Name of the property that defines the default channel capacity when BUFFERED is used as parameter in Channel(...) factory function.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
const val RENDEZVOUS: Int = 0

Requests a rendezvous channel in the Channel(...) factory function — a channel that does not have a buffer.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
const val UNLIMITED: Int

Requests a channel with an unlimited capacity buffer in the Channel(...) factory function.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/index.html index 9e2c62537d..2da2cd9d03 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-channel/index.html @@ -1,96 +1 @@ - - - - - Channel - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Channel

-
-
-
interface Channel<E> : SendChannel<E> , ReceiveChannel<E>

Channel is a non-blocking primitive for communication between a sender (via SendChannel) and a receiver (via ReceiveChannel). Conceptually, a channel is similar to Java's java.util.concurrent.BlockingQueue, but it has suspending operations instead of blocking ones and can be closed.

Creating channels

The Channel(capacity) factory function is used to create channels of different kinds depending on the value of the capacity integer:

  • When capacity is 0 — it creates a rendezvous channel. This channel does not have any buffer at all. An element is transferred from the sender to the receiver only when send and receive invocations meet in time (rendezvous), so send suspends until another coroutine invokes receive, and receive suspends until another coroutine invokes send.

  • When capacity is Channel.UNLIMITED — it creates a channel with effectively unlimited buffer. This channel has a linked-list buffer of unlimited capacity (limited only by available memory). Sending to this channel never suspends, and trySend always succeeds.

  • When capacity is Channel.CONFLATED — it creates a conflated channel This channel buffers at most one element and conflates all subsequent send and trySend invocations, so that the receiver always gets the last element sent. Back-to-back sent elements are conflated — only the last sent element is received, while previously sent elements are lost. Sending to this channel never suspends, and trySend always succeeds.

  • When capacity is positive but less than UNLIMITED — it creates an array-based channel with the specified capacity. This channel has an array buffer of a fixed capacity. Sending suspends only when the buffer is full, and receiving suspends only when the buffer is empty.

Buffered channels can be configured with an additional onBufferOverflow parameter. It controls the behaviour of the channel's send function on buffer overflow:

  • SUSPEND — the default, suspend send on buffer overflow until there is free space in the buffer.

  • DROP_OLDEST — do not suspend the send, add the latest value to the buffer, drop the oldest one from the buffer. A channel with capacity = 1 and onBufferOverflow = DROP_OLDEST is a conflated channel.

  • DROP_LATEST — do not suspend the send, drop the value that is being sent, keep the buffer contents intact.

A non-default onBufferOverflow implicitly creates a channel with at least one buffered element and is ignored for a channel with unlimited buffer. It cannot be specified for capacity = CONFLATED, which is a shortcut by itself.

Prompt cancellation guarantee

All suspending functions with channels provide prompt cancellation guarantee. If the job was cancelled while send or receive function was suspended, it will not resume successfully, but throws a CancellationException. With a single-threaded dispatcher like Dispatchers.Main this gives a guarantee that if a piece code running in this thread cancels a Job, then a coroutine running this job cannot resume successfully and continue to run, ensuring a prompt response to its cancellation.

Prompt cancellation guarantee for channel operations was added since kotlinx.coroutines version 1.4.0 and had replaced a channel-specific atomic-cancellation that was not consistent with other suspending functions. The low-level mechanics of prompt cancellation are explained in suspendCancellableCoroutine function.

Undelivered elements

As a result of a prompt cancellation guarantee, when a closeable resource (like open file or a handle to another native resource) is transferred via channel from one coroutine to another it can fail to be delivered and will be lost if either send or receive operations are cancelled in transit.

A Channel() constructor function has an onUndeliveredElement optional parameter. When onUndeliveredElement parameter is set, the corresponding function is called once for each element that was sent to the channel with the call to the send function but failed to be delivered, which can happen in the following cases:

  • When send operation throws an exception because it was cancelled before it had a chance to actually send the element or because the channel was closed or cancelled.

  • When receive, receiveOrNull, or hasNext operation throws an exception when it had retrieved the element from the channel but was cancelled before the code following the receive call resumed.

  • The channel was cancelled, in which case onUndeliveredElement is called on every remaining element in the channel's buffer.

Note, that onUndeliveredElement function is called synchronously in an arbitrary context. It should be fast, non-blocking, and should not throw exceptions. Any exception thrown by onUndeliveredElement is wrapped into an internal runtime exception which is either rethrown from the caller method or handed off to the exception handler in the current context (see CoroutineExceptionHandler) when one is available.

A typical usage for onUndeliveredElement is to close a resource that is being transferred via the channel. The following code pattern guarantees that opened resources are closed even if producer, consumer, and/or channel are cancelled. Resources are never lost.

// Create the channel with onUndeliveredElement block that closes a resource
val channel = Channel<Resource>(capacity) { resource -> resource.close() }

// Producer code
val resourceToSend = openResource()
channel.send(resourceToSend)

// Consumer code
val resourceReceived = channel.receive()
try {
// work with received resource
} finally {
resourceReceived.close()
}

Note, that if you do any kind of work in between openResource() and channel.send(...), then you should ensure that resource gets closed in case this additional code fails.

-
-
-
-
-

Types

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
object Factory

Constants for the channel factory function Channel().

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-closed-receive-channel-exception/-closed-receive-channel-exception.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-closed-receive-channel-exception/-closed-receive-channel-exception.html index 6475b6f229..5eefca1ae0 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-closed-receive-channel-exception/-closed-receive-channel-exception.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-closed-receive-channel-exception/-closed-receive-channel-exception.html @@ -1,72 +1 @@ - - - - - ClosedReceiveChannelException - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

ClosedReceiveChannelException

-
-
-
-
fun ClosedReceiveChannelException(message: String?)
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-closed-receive-channel-exception/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-closed-receive-channel-exception/index.html index 3890201e0b..1263774c14 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-closed-receive-channel-exception/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-closed-receive-channel-exception/index.html @@ -1,96 +1 @@ - - - - - ClosedReceiveChannelException - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

ClosedReceiveChannelException

-
-
-
class ClosedReceiveChannelException(message: String?) : NoSuchElementException

Indicates an attempt to receive from a isClosedForReceive channel that was closed without a cause. A failed channel rethrows the original close cause exception on receive attempts.

This exception is a subclass of NoSuchElementException to be consistent with plain collections.

-
-
-
-
-

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun ClosedReceiveChannelException(message: String?)
-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-closed-send-channel-exception/-closed-send-channel-exception.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-closed-send-channel-exception/-closed-send-channel-exception.html index 690318109f..f48b09d214 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-closed-send-channel-exception/-closed-send-channel-exception.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-closed-send-channel-exception/-closed-send-channel-exception.html @@ -1,72 +1 @@ - - - - - ClosedSendChannelException - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

ClosedSendChannelException

-
-
-
-
fun ClosedSendChannelException(message: String?)
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-closed-send-channel-exception/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-closed-send-channel-exception/index.html index 46ccaf4010..f2f8d2607f 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-closed-send-channel-exception/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-closed-send-channel-exception/index.html @@ -1,96 +1 @@ - - - - - ClosedSendChannelException - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

ClosedSendChannelException

-
-
-
class ClosedSendChannelException(message: String?) : IllegalStateException

Indicates an attempt to send to a isClosedForSend channel that was closed without a cause. A failed channel rethrows the original close cause exception on send attempts.

This exception is a subclass of IllegalStateException, because, conceptually, it is the sender's responsibility to close the channel and not try to send anything thereafter. Attempts to send to a closed channel indicate a logical error in the sender's code.

-
-
-
-
-

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun ClosedSendChannelException(message: String?)
-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/-conflated-broadcast-channel.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/-conflated-broadcast-channel.html index 62f7ac3cb5..585d9d4ed1 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/-conflated-broadcast-channel.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/-conflated-broadcast-channel.html @@ -1,83 +1 @@ - - - - - ConflatedBroadcastChannel - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

ConflatedBroadcastChannel

-
-
-
-
fun <E> ConflatedBroadcastChannel(value: E)

Creates an instance of this class that already holds a value.

It is as a shortcut to creating an instance with a default constructor and immediately sending an element: ConflatedBroadcastChannel().apply { offer(value) }.


fun ConflatedBroadcastChannel()
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/cancel.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/cancel.html index 772982fa93..43cf543d6e 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/cancel.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/cancel.html @@ -1,72 +1 @@ - - - - - cancel - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

cancel

-
-
-
-
open override fun cancel(cause: CancellationException?)

Cancels this conflated broadcast channel with an optional cause, same as close. This function closes the channel with the specified cause (unless it was already closed), and cancels all open subscriptions. A cause can be used to specify an error message or to provide other details on a cancellation reason for debugging purposes.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/close.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/close.html index 9e11745d55..0709f7b4e3 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/close.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/close.html @@ -1,72 +1 @@ - - - - - close - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

close

-
-
-
-
open override fun close(cause: Throwable?): Boolean

Closes this channel. This is an idempotent operation — subsequent invocations of this function have no effect and return false. Conceptually, it sends a special "close token" over this channel.

Immediately after invocation of this function, isClosedForSend starts returning true. However, isClosedForReceive on the side of ReceiveChannel starts returning true only after all previously sent elements are received.

A channel that was closed without a cause throws a ClosedSendChannelException on attempts to send and ClosedReceiveChannelException on attempts to receive. A channel that was closed with non-null cause is called a failed channel. Attempts to send or receive on a failed channel throw the specified cause exception.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/index.html index 0181ff90d7..83a138b2f5 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/index.html @@ -1,287 +1 @@ - - - - - ConflatedBroadcastChannel - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

ConflatedBroadcastChannel

-
-
-

Broadcasts the most recently sent element (aka value) to all openSubscription subscribers.

Back-to-send sent elements are conflated -- only the the most recently sent value is received, while previously sent elements are lost. Every subscriber immediately receives the most recently sent element. Sender to this broadcast channel never suspends and trySend always succeeds.

A secondary constructor can be used to create an instance of this class that already holds a value. This channel is also created by BroadcastChannel(Channel.CONFLATED) factory function invocation.

This implementation is fully lock-free. In this implementation opening and closing subscription takes O(N) time, where N is the number of subscribers.

Note: This API is obsolete since 1.5.0. It will be deprecated with warning in 1.6.0 and with error in 1.7.0. It is replaced with StateFlow.

-
-
-
-
-

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <E> ConflatedBroadcastChannel(value: E)

Creates an instance of this class that already holds a value.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun ConflatedBroadcastChannel()
-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
open override fun cancel(cause: CancellationException?)

Cancels this conflated broadcast channel with an optional cause, same as close. This function closes the channel with the specified cause (unless it was already closed), and cancels all open subscriptions. A cause can be used to specify an error message or to provide other details on a cancellation reason for debugging purposes.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
open override fun close(cause: Throwable?): Boolean

Closes this channel. This is an idempotent operation — subsequent invocations of this function have no effect and return false. Conceptually, it sends a special "close token" over this channel.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
open override fun invokeOnClose(handler: Handler)

Registers a handler which is synchronously invoked once the channel is closed or the receiving side of this channel is cancelled. Only one handler can be attached to a channel during its lifetime. The handler is invoked when isClosedForSend starts to return true. If the channel is closed already, the handler is invoked immediately.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
open override fun openSubscription(): ReceiveChannel<E>

Subscribes to this BroadcastChannel and returns a channel to receive elements from it. The resulting channel shall be cancelled to unsubscribe from this broadcast channel.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
open suspend override fun send(element: E)

Sends the value to all subscribed receives and stores this value as the most recent state for future subscribers. This implementation never suspends. It throws exception if the channel isClosedForSend (see close for details).

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
open override fun trySend(element: E): ChannelResult<Unit>

Sends the value to all subscribed receives and stores this value as the most recent state for future subscribers. This implementation always returns either successful result or closed with an exception.

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
open override val isClosedForSend: Boolean

Returns true if this channel was closed by an invocation of close. This means that calling send will result in an exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
open override val onSend: SelectClause2<E, SendChannel<E>>

Clause for the select expression of the send suspending function that selects when the element that is specified as the parameter is sent to the channel. When the clause is selected, the reference to this channel is passed into the corresponding block.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
val value: E

The most recently sent element to this channel.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
val valueOrNull: E?

The most recently sent element to this channel or null when this class is constructed without initial value and no value was sent yet or if it was closed.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/invoke-on-close.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/invoke-on-close.html index e4e878d424..54373c40be 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/invoke-on-close.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/invoke-on-close.html @@ -1,72 +1 @@ - - - - - invokeOnClose - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

invokeOnClose

-
-
-
-
open override fun invokeOnClose(handler: Handler)

Registers a handler which is synchronously invoked once the channel is closed or the receiving side of this channel is cancelled. Only one handler can be attached to a channel during its lifetime. The handler is invoked when isClosedForSend starts to return true. If the channel is closed already, the handler is invoked immediately.

The meaning of cause that is passed to the handler:

  • null if the channel was closed or cancelled without the corresponding argument

  • the cause of close or cancel otherwise.

Example of usage (exception handling is omitted):

val events = Channel(UNLIMITED)
callbackBasedApi.registerCallback { event ->
events.trySend(event)
}

val uiUpdater = launch(Dispatchers.Main, parent = UILifecycle) {
events.consume {}
events.cancel()
}

events.invokeOnClose { callbackBasedApi.stop() }

Note: This is an experimental api. This function may change its semantics, parameters or return type in the future.

Throws

if the underlying channel doesn't support invokeOnClose. Implementation note: currently, invokeOnClose is unsupported only by Rx-like integrations

if another handler was already registered

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/is-closed-for-send.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/is-closed-for-send.html index 626daaf122..d1ff4fcec3 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/is-closed-for-send.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/is-closed-for-send.html @@ -1,72 +1 @@ - - - - - isClosedForSend - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

isClosedForSend

-
-
-
-
open override val isClosedForSend: Boolean

Returns true if this channel was closed by an invocation of close. This means that calling send will result in an exception.

Note: This is an experimental api. This property may change its semantics and/or name in the future.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/on-send.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/on-send.html index aca12f5ec9..eb0b8cf7f9 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/on-send.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/on-send.html @@ -1,72 +1 @@ - - - - - onSend - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

onSend

-
-
-
-
open override val onSend: SelectClause2<E, SendChannel<E>>

Clause for the select expression of the send suspending function that selects when the element that is specified as the parameter is sent to the channel. When the clause is selected, the reference to this channel is passed into the corresponding block.

The select invocation fails with an exception if the channel is closed for send (see close for details).

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/open-subscription.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/open-subscription.html index 51d0622892..35865f6b3f 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/open-subscription.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/open-subscription.html @@ -1,72 +1 @@ - - - - - openSubscription - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

openSubscription

-
-
-
-
open override fun openSubscription(): ReceiveChannel<E>

Subscribes to this BroadcastChannel and returns a channel to receive elements from it. The resulting channel shall be cancelled to unsubscribe from this broadcast channel.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/send.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/send.html index e89c7c1c84..30b279026e 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/send.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/send.html @@ -1,72 +1 @@ - - - - - send - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

send

-
-
-
-
open suspend override fun send(element: E)

Sends the value to all subscribed receives and stores this value as the most recent state for future subscribers. This implementation never suspends. It throws exception if the channel isClosedForSend (see close for details).

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/try-send.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/try-send.html index 3efa6e9b77..9e2a60f1a9 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/try-send.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/try-send.html @@ -1,72 +1 @@ - - - - - trySend - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

trySend

-
-
-
-
open override fun trySend(element: E): ChannelResult<Unit>

Sends the value to all subscribed receives and stores this value as the most recent state for future subscribers. This implementation always returns either successful result or closed with an exception.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/value-or-null.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/value-or-null.html index 500a48edbc..bcae9b12d1 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/value-or-null.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/value-or-null.html @@ -1,72 +1 @@ - - - - - valueOrNull - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

valueOrNull

-
-
-
-
val valueOrNull: E?

The most recently sent element to this channel or null when this class is constructed without initial value and no value was sent yet or if it was closed.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/value.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/value.html index 5866901040..71a167a5b0 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/value.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-conflated-broadcast-channel/value.html @@ -1,72 +1 @@ - - - - - value - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

value

-
-
-
-
val value: E

The most recently sent element to this channel.

Access to this property throws IllegalStateException when this class is constructed without initial value and no value was sent yet or if it was closed without a cause. It throws the original close cause exception if the channel has failed.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-producer-scope/channel.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-producer-scope/channel.html index 65209f5526..cea3fa600a 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-producer-scope/channel.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-producer-scope/channel.html @@ -1,72 +1 @@ - - - - - channel - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

channel

-
-
-
-
abstract val channel: SendChannel<E>

A reference to the channel this coroutine sends elements to. It is provided for convenience, so that the code in the coroutine can refer to the channel as channel as opposed to this. All the SendChannel functions on this interface delegate to the channel instance returned by this property.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-producer-scope/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-producer-scope/index.html index 4d92111419..d73177c28e 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-producer-scope/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-producer-scope/index.html @@ -1,115 +1 @@ - - - - - ProducerScope - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

ProducerScope

-
-
-
interface ProducerScope<in E> : CoroutineScope, SendChannel<E>

Scope for the produce, callbackFlow and channelFlow builders.

-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val channel: SendChannel<E>

A reference to the channel this coroutine sends elements to. It is provided for convenience, so that the code in the coroutine can refer to the channel as channel as opposed to this. All the SendChannel functions on this interface delegate to the channel instance returned by this property.

-
-
-
-
-
-

Extensions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun ProducerScope<*>.awaitClose(block: () -> Unit = {})

Suspends the current coroutine until the channel is either closed or cancelled and invokes the given block before resuming the coroutine.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/cancel.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/cancel.html index b3a60eee6b..926fbd7807 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/cancel.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/cancel.html @@ -1,72 +1 @@ - - - - - cancel - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

cancel

-
-
-
-
abstract fun cancel(cause: CancellationException? = null)

Cancels reception of remaining elements from this channel with an optional cause. This function closes the channel and removes all buffered sent elements from it.

A cause can be used to specify an error message or to provide other details on the cancellation reason for debugging purposes. If the cause is not specified, then an instance of CancellationException with a default message is created to close the channel.

Immediately after invocation of this function isClosedForReceive and isClosedForSend on the side of SendChannel start returning true. Any attempt to send to or receive from this channel will lead to a CancellationException.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/index.html index a9a27d76df..5d48080c68 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/index.html @@ -1,380 +1 @@ - - - - - ReceiveChannel - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

ReceiveChannel

-
-
-
interface ReceiveChannel<out E>

Receiver's interface to Channel.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun cancel(cause: CancellationException? = null)

Cancels reception of remaining elements from this channel with an optional cause. This function closes the channel and removes all buffered sent elements from it.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract operator fun iterator(): ChannelIterator<E>

Returns a new iterator to receive elements from this channel using a for loop. Iteration completes normally when the channel is closed for receive without a cause and throws the original close cause exception if the channel has failed.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract suspend fun receive(): E

Retrieves and removes an element from this channel if it's not empty, or suspends the caller while the channel is empty, or throws a ClosedReceiveChannelException if the channel is closed for receive. If the channel was closed because of an exception, it is called a failed channel and this function will throw the original close cause exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract suspend fun receiveCatching(): ChannelResult<E>

Retrieves and removes an element from this channel if it's not empty, or suspends the caller while this channel is empty. This method returns ChannelResult with the value of an element successfully retrieved from the channel or the close cause if the channel was closed. Closed cause may be null if the channel was closed normally. The result cannot be failed without being closed.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun tryReceive(): ChannelResult<E>

Retrieves and removes an element from this channel if it's not empty, returning a successful result, returns failed result if the channel is empty, and closed result if the channel is closed.

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val isClosedForReceive: Boolean

Returns true if this channel was closed by invocation of close on the SendChannel side and all previously sent items were already received. This means that calling receive will result in a ClosedReceiveChannelException. If the channel was closed because of an exception, it is considered closed, too, but is called a failed channel. All suspending attempts to receive an element from a failed channel throw the original close cause exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val isEmpty: Boolean

Returns true if the channel is empty (contains no elements), which means that an attempt to receive will suspend. This function returns false if the channel is closed for receive.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val onReceive: SelectClause1<E>

Clause for the select expression of the receive suspending function that selects with the element received from the channel. The select invocation fails with an exception if the channel is closed for receive (see close for details).

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val onReceiveCatching: SelectClause1<ChannelResult<E>>

Clause for the select expression of the onReceiveCatching suspending function that selects with the ChannelResult with a value that is received from the channel or with a close cause if the channel is closed for receive.

-
-
-
-
-
-

Inheritors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Extensions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <E> ReceiveChannel<E>.broadcast(capacity: Int = 1, start: CoroutineStart = CoroutineStart.LAZY): BroadcastChannel<E>

Broadcasts all elements of the channel. This function consumes all elements of the original ReceiveChannel.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <E, R> ReceiveChannel<E>.consume(block: ReceiveChannel<E>.() -> R): R

Makes sure that the given block consumes all elements from the given channel by always invoking cancel after the execution of the block.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> ReceiveChannel<T>.consumeAsFlow(): Flow<T>

Represents the given receive channel as a hot flow and consumes the channel on the first collection from this flow. The resulting flow can be collected just once and throws IllegalStateException when trying to collect it more than once.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline suspend fun <E> ReceiveChannel<E>.consumeEach(action: (E) -> Unit)

Performs the given action for each received element and cancels the channel after the execution of the block. If you need to iterate over the channel without consuming it, a regular for loop should be used instead.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <E : Any> ReceiveChannel<E>.onReceiveOrNull(): SelectClause1<E?>

This function is deprecated in the favour of ReceiveChannel.onReceiveCatching

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> ReceiveChannel<T>.receiveAsFlow(): Flow<T>

Represents the given receive channel as a hot flow and receives from the channel in fan-out fashion every time this flow is collected. One element will be emitted to one collector only.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <E> ReceiveChannel<E>.toList(): List<E>

Returns a List containing all elements.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/is-closed-for-receive.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/is-closed-for-receive.html index db79ac00c0..c21ece2ae4 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/is-closed-for-receive.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/is-closed-for-receive.html @@ -1,72 +1 @@ - - - - - isClosedForReceive - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

isClosedForReceive

-
-
-
-
abstract val isClosedForReceive: Boolean

Returns true if this channel was closed by invocation of close on the SendChannel side and all previously sent items were already received. This means that calling receive will result in a ClosedReceiveChannelException. If the channel was closed because of an exception, it is considered closed, too, but is called a failed channel. All suspending attempts to receive an element from a failed channel throw the original close cause exception.

Note: This is an experimental api. This property may change its semantics and/or name in the future.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/is-empty.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/is-empty.html index bd2888f577..742094cdac 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/is-empty.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/is-empty.html @@ -1,72 +1 @@ - - - - - isEmpty - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

isEmpty

-
-
-
-
abstract val isEmpty: Boolean

Returns true if the channel is empty (contains no elements), which means that an attempt to receive will suspend. This function returns false if the channel is closed for receive.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/iterator.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/iterator.html index e27a77f65f..3dfeeeb420 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/iterator.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/iterator.html @@ -1,72 +1 @@ - - - - - iterator - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

iterator

-
-
-
-
abstract operator fun iterator(): ChannelIterator<E>

Returns a new iterator to receive elements from this channel using a for loop. Iteration completes normally when the channel is closed for receive without a cause and throws the original close cause exception if the channel has failed.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/on-receive-catching.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/on-receive-catching.html index 51566eb95b..4ffdf9c835 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/on-receive-catching.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/on-receive-catching.html @@ -1,72 +1 @@ - - - - - onReceiveCatching - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

onReceiveCatching

-
-
-
-
abstract val onReceiveCatching: SelectClause1<ChannelResult<E>>

Clause for the select expression of the onReceiveCatching suspending function that selects with the ChannelResult with a value that is received from the channel or with a close cause if the channel is closed for receive.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/on-receive.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/on-receive.html index 7387197050..cb3246ad1a 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/on-receive.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/on-receive.html @@ -1,72 +1 @@ - - - - - onReceive - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

onReceive

-
-
-
-
abstract val onReceive: SelectClause1<E>

Clause for the select expression of the receive suspending function that selects with the element received from the channel. The select invocation fails with an exception if the channel is closed for receive (see close for details).

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/receive-catching.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/receive-catching.html index 7b7fcfc8c6..2389a6e99d 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/receive-catching.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/receive-catching.html @@ -1,72 +1 @@ - - - - - receiveCatching - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

receiveCatching

-
-
-
-
abstract suspend fun receiveCatching(): ChannelResult<E>

Retrieves and removes an element from this channel if it's not empty, or suspends the caller while this channel is empty. This method returns ChannelResult with the value of an element successfully retrieved from the channel or the close cause if the channel was closed. Closed cause may be null if the channel was closed normally. The result cannot be failed without being closed.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this function is suspended, this function immediately resumes with a CancellationException. There is a prompt cancellation guarantee. If the job was cancelled while this function was suspended, it will not resume successfully. The receiveCatching call can retrieve the element from the channel, but then throw CancellationException, thus failing to deliver the element. See "Undelivered elements" section in Channel documentation for details on handling undelivered elements.

Note that this function does not check for cancellation when it is not suspended. Use yield or CoroutineScope.isActive to periodically check for cancellation in tight loops if needed.

This function can be used in select invocations with the onReceiveCatching clause. Use tryReceive to try receiving from this channel without waiting.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/receive.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/receive.html index 62f4e21742..b1befe26b5 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/receive.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/receive.html @@ -1,72 +1 @@ - - - - - receive - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

receive

-
-
-
-
abstract suspend fun receive(): E

Retrieves and removes an element from this channel if it's not empty, or suspends the caller while the channel is empty, or throws a ClosedReceiveChannelException if the channel is closed for receive. If the channel was closed because of an exception, it is called a failed channel and this function will throw the original close cause exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this function is suspended, this function immediately resumes with a CancellationException. There is a prompt cancellation guarantee. If the job was cancelled while this function was suspended, it will not resume successfully. The receive call can retrieve the element from the channel, but then throw CancellationException, thus failing to deliver the element. See "Undelivered elements" section in Channel documentation for details on handling undelivered elements.

Note that this function does not check for cancellation when it is not suspended. Use yield or CoroutineScope.isActive to periodically check for cancellation in tight loops if needed.

This function can be used in select invocations with the onReceive clause. Use tryReceive to try receiving from this channel without waiting.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/try-receive.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/try-receive.html index 63e6140ae2..7d05bcb154 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/try-receive.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-receive-channel/try-receive.html @@ -1,72 +1 @@ - - - - - tryReceive - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

tryReceive

-
-
-
-
abstract fun tryReceive(): ChannelResult<E>

Retrieves and removes an element from this channel if it's not empty, returning a successful result, returns failed result if the channel is empty, and closed result if the channel is closed.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/close.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/close.html index 3eeaab9199..f77b2e5584 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/close.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/close.html @@ -1,72 +1 @@ - - - - - close - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

close

-
-
-
-
abstract fun close(cause: Throwable? = null): Boolean

Closes this channel. This is an idempotent operation — subsequent invocations of this function have no effect and return false. Conceptually, it sends a special "close token" over this channel.

Immediately after invocation of this function, isClosedForSend starts returning true. However, isClosedForReceive on the side of ReceiveChannel starts returning true only after all previously sent elements are received.

A channel that was closed without a cause throws a ClosedSendChannelException on attempts to send and ClosedReceiveChannelException on attempts to receive. A channel that was closed with non-null cause is called a failed channel. Attempts to send or receive on a failed channel throw the specified cause exception.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/index.html index 4b93ba429a..932975ed0c 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/index.html @@ -1,238 +1 @@ - - - - - SendChannel - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

SendChannel

-
-
-
interface SendChannel<in E>

Sender's interface to Channel.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun close(cause: Throwable? = null): Boolean

Closes this channel. This is an idempotent operation — subsequent invocations of this function have no effect and return false. Conceptually, it sends a special "close token" over this channel.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun invokeOnClose(handler: (cause: Throwable?) -> Unit)

Registers a handler which is synchronously invoked once the channel is closed or the receiving side of this channel is cancelled. Only one handler can be attached to a channel during its lifetime. The handler is invoked when isClosedForSend starts to return true. If the channel is closed already, the handler is invoked immediately.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract suspend fun send(element: E)

Sends the specified element to this channel, suspending the caller while the buffer of this channel is full or if it does not exist, or throws an exception if the channel is closed for send (see close for details).

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun trySend(element: E): ChannelResult<Unit>

Immediately adds the specified element to this channel, if this doesn't violate its capacity restrictions, and returns the successful result. Otherwise, returns failed or closed result. This is synchronous variant of send, which backs off in situations when send suspends or throws.

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val isClosedForSend: Boolean

Returns true if this channel was closed by an invocation of close. This means that calling send will result in an exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val onSend: SelectClause2<E, SendChannel<E>>

Clause for the select expression of the send suspending function that selects when the element that is specified as the parameter is sent to the channel. When the clause is selected, the reference to this channel is passed into the corresponding block.

-
-
-
-
-
-

Inheritors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Extensions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <E> SendChannel<E>.trySendBlocking(element: E): ChannelResult<Unit>

Adds element to this channel, blocking the caller while this channel is full, and returning either successful result when the element was added, or failed result representing closed channel with a corresponding exception.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/invoke-on-close.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/invoke-on-close.html index 591bb7428d..715a2df4a4 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/invoke-on-close.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/invoke-on-close.html @@ -1,72 +1 @@ - - - - - invokeOnClose - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

invokeOnClose

-
-
-
-
abstract fun invokeOnClose(handler: (cause: Throwable?) -> Unit)

Registers a handler which is synchronously invoked once the channel is closed or the receiving side of this channel is cancelled. Only one handler can be attached to a channel during its lifetime. The handler is invoked when isClosedForSend starts to return true. If the channel is closed already, the handler is invoked immediately.

The meaning of cause that is passed to the handler:

  • null if the channel was closed or cancelled without the corresponding argument

  • the cause of close or cancel otherwise.

Example of usage (exception handling is omitted):

val events = Channel(UNLIMITED)
callbackBasedApi.registerCallback { event ->
events.trySend(event)
}

val uiUpdater = launch(Dispatchers.Main, parent = UILifecycle) {
events.consume {}
events.cancel()
}

events.invokeOnClose { callbackBasedApi.stop() }

Note: This is an experimental api. This function may change its semantics, parameters or return type in the future.

Throws

if the underlying channel doesn't support invokeOnClose. Implementation note: currently, invokeOnClose is unsupported only by Rx-like integrations

if another handler was already registered

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/is-closed-for-send.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/is-closed-for-send.html index aa5766870e..f0268632e9 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/is-closed-for-send.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/is-closed-for-send.html @@ -1,72 +1 @@ - - - - - isClosedForSend - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

isClosedForSend

-
-
-
-
abstract val isClosedForSend: Boolean

Returns true if this channel was closed by an invocation of close. This means that calling send will result in an exception.

Note: This is an experimental api. This property may change its semantics and/or name in the future.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/on-send.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/on-send.html index ff52257b6d..d317c4afb3 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/on-send.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/on-send.html @@ -1,72 +1 @@ - - - - - onSend - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

onSend

-
-
-
-
abstract val onSend: SelectClause2<E, SendChannel<E>>

Clause for the select expression of the send suspending function that selects when the element that is specified as the parameter is sent to the channel. When the clause is selected, the reference to this channel is passed into the corresponding block.

The select invocation fails with an exception if the channel is closed for send (see close for details).

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/send.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/send.html index 1eb8bc4497..0f9f451465 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/send.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/send.html @@ -1,72 +1 @@ - - - - - send - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

send

-
-
-
-
abstract suspend fun send(element: E)

Sends the specified element to this channel, suspending the caller while the buffer of this channel is full or if it does not exist, or throws an exception if the channel is closed for send (see close for details).

Closing a channel after this function has suspended does not cause this suspended send invocation to abort, because closing a channel is conceptually like sending a special "close token" over this channel. All elements sent over the channel are delivered in first-in first-out order. The sent element will be delivered to receivers before the close token.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this function is suspended, this function immediately resumes with a CancellationException. There is a prompt cancellation guarantee. If the job was cancelled while this function was suspended, it will not resume successfully. The send call can send the element to the channel, but then throw CancellationException, thus an exception should not be treated as a failure to deliver the element. See "Undelivered elements" section in Channel documentation for details on handling undelivered elements.

Note that this function does not check for cancellation when it is not suspended. Use yield or CoroutineScope.isActive to periodically check for cancellation in tight loops if needed.

This function can be used in select invocations with the onSend clause. Use trySend to try sending to this channel without waiting.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/try-send.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/try-send.html index 004e6331db..828bb7151e 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/try-send.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-send-channel/try-send.html @@ -1,72 +1 @@ - - - - - trySend - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

trySend

-
-
-
-
abstract fun trySend(element: E): ChannelResult<Unit>

Immediately adds the specified element to this channel, if this doesn't violate its capacity restrictions, and returns the successful result. Otherwise, returns failed or closed result. This is synchronous variant of send, which backs off in situations when send suspends or throws.

When trySend call returns a non-successful result, it guarantees that the element was not delivered to the consumer, and it does not call onUndeliveredElement that was installed for this channel. See "Undelivered elements" section in Channel documentation for details on handling undelivered elements.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-ticker-mode/-f-i-x-e-d_-d-e-l-a-y/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-ticker-mode/-f-i-x-e-d_-d-e-l-a-y/index.html index 873b9379ef..b7f7497c82 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-ticker-mode/-f-i-x-e-d_-d-e-l-a-y/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-ticker-mode/-f-i-x-e-d_-d-e-l-a-y/index.html @@ -1,63 +1 @@ - - - - - FIXED_DELAY - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

FIXED_DELAY

-
-
-

Maintains fixed delay between produced elements if consumer cannot keep up or it otherwise slow.

-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-ticker-mode/-f-i-x-e-d_-p-e-r-i-o-d/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-ticker-mode/-f-i-x-e-d_-p-e-r-i-o-d/index.html index f3daa1c8ba..7784030f88 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-ticker-mode/-f-i-x-e-d_-p-e-r-i-o-d/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-ticker-mode/-f-i-x-e-d_-p-e-r-i-o-d/index.html @@ -1,63 +1 @@ - - - - - FIXED_PERIOD - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

FIXED_PERIOD

-
-
-

Adjust delay to maintain fixed period if consumer cannot keep up or is otherwise slow. This is a default mode.

val channel = ticker(delay = 100)
delay(350) // 250 ms late
println(channel.tryReceive().getOrNull()) // prints Unit
println(channel.tryReceive().getOrNull()) // prints null

delay(50)
println(channel.tryReceive().getOrNull()) // prints Unit, delay was adjusted
delay(50)
println(channel.tryReceive().getOrNull()) // prints null, we're not late relatively to previous element
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-ticker-mode/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-ticker-mode/index.html index 628a74fae0..66877f25a3 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/-ticker-mode/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/-ticker-mode/index.html @@ -1,113 +1 @@ - - - - - TickerMode - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

TickerMode

-
-
-
enum TickerMode : Enum<TickerMode>

Mode for ticker function.

Note: Ticker channels are not currently integrated with structured concurrency and their api will change in the future.

-
-
-
-
-

Entries

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Maintains fixed delay between produced elements if consumer cannot keep up or it otherwise slow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Adjust delay to maintain fixed period if consumer cannot keep up or is otherwise slow. This is a default mode.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/actor.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/actor.html index 7115f16932..d91d065f55 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/actor.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/actor.html @@ -1,72 +1 @@ - - - - - actor - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

actor

-
-
-
-
fun <E> CoroutineScope.actor(    context: CoroutineContext = EmptyCoroutineContext,     capacity: Int = 0,     start: CoroutineStart = CoroutineStart.DEFAULT,     onCompletion: CompletionHandler? = null,     block: suspend ActorScope<E>.() -> Unit): SendChannel<E>

Launches new coroutine that is receiving messages from its mailbox channel and returns a reference to its mailbox channel as a SendChannel. The resulting object can be used to send messages to this coroutine.

The scope of the coroutine contains ActorScope interface, which implements both CoroutineScope and ReceiveChannel, so that coroutine can invoke receive directly. The channel is closed when the coroutine completes.

Coroutine context is inherited from a CoroutineScope, additional context elements can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. The parent job is inherited from a CoroutineScope as well, but it can also be overridden with corresponding context element.

By default, the coroutine is immediately scheduled for execution. Other options can be specified via start parameter. See CoroutineStart for details. An optional start parameter can be set to CoroutineStart.LAZY to start coroutine lazily. In this case, it will be started implicitly on the first message sent to this actors's mailbox channel.

Uncaught exceptions in this coroutine close the channel with this exception as a cause and the resulting channel becomes failed, so that any attempt to send to such a channel throws exception.

The kind of the resulting channel depends on the specified capacity parameter. See Channel interface documentation for details.

See newCoroutineContext for a description of debugging facilities that are available for newly created coroutine.

Using actors

A typical usage of the actor builder looks like this:

val c = actor {
// initialize actor's state
for (msg in channel) {
// process message here
}
}
// send messages to the actor
c.send(...)
...
// stop the actor when it is no longer needed
c.close()

Stopping and cancelling actors

When the inbox channel of the actor is closed it sends a special "close token" to the actor. The actor still processes all the messages that were already sent and then "for (msg in channel)" loop terminates and the actor completes.

If the actor needs to be aborted without processing all the messages that were already sent to it, then it shall be created with a parent job:

val job = Job()
val c = actor(context = job) { ... }
...
// abort the actor
job.cancel()

When actor's parent job is cancelled, then actor's job becomes cancelled. It means that "for (msg in channel)" and other cancellable suspending functions throw CancellationException and actor completes without processing remaining messages.

Note: This API will become obsolete in future updates with introduction of complex actors. See issue #87.

Parameters

context

additional to CoroutineScope.coroutineContext context of the coroutine.

capacity

capacity of the channel's buffer (no buffer by default).

start

coroutine start option. The default value is CoroutineStart.DEFAULT.

onCompletion

optional completion handler for the actor coroutine (see Job.invokeOnCompletion)

block

the coroutine code.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/await-close.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/await-close.html index f36077b5af..ea6015a2cd 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/await-close.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/await-close.html @@ -1,72 +1 @@ - - - - - awaitClose - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitClose

-
-
-
-
suspend fun ProducerScope<*>.awaitClose(block: () -> Unit = {})

Suspends the current coroutine until the channel is either closed or cancelled and invokes the given block before resuming the coroutine.

This suspending function is cancellable. There is a prompt cancellation guarantee. If the job was cancelled while this function was suspended, it will not resume successfully. See suspendCancellableCoroutine documentation for low-level details.

Note that when the producer channel is cancelled, this function resumes with a cancellation exception. Therefore, in case of cancellation, no code after the call to this function will be executed. That's why this function takes a lambda parameter.

Example of usage:

val callbackEventsStream = produce {
val disposable = registerChannelInCallback(channel)
awaitClose { disposable.dispose() }
}
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/broadcast.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/broadcast.html index 759bc22c0e..1ab0e6a83a 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/broadcast.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/broadcast.html @@ -1,83 +1 @@ - - - - - broadcast - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

broadcast

-
-
-
-
fun <E> ReceiveChannel<E>.broadcast(capacity: Int = 1, start: CoroutineStart = CoroutineStart.LAZY): BroadcastChannel<E>

Broadcasts all elements of the channel. This function consumes all elements of the original ReceiveChannel.

The kind of the resulting channel depends on the specified capacity parameter: when capacity is positive (1 by default), but less than UNLIMITED -- uses ArrayBroadcastChannel with a buffer of given capacity, when capacity is CONFLATED -- uses ConflatedBroadcastChannel that conflates back-to-back sends; Note that resulting channel behaves like ConflatedBroadcastChannel but is not an instance of ConflatedBroadcastChannel. otherwise -- throws IllegalArgumentException.

Cancelling broadcast

To stop broadcasting from the underlying channel call cancel on the result.

Do not use close on the resulting channel. It causes eventual failure of the broadcast coroutine and cancellation of the underlying channel, too, but it is not as prompt.

Future replacement

This function has an inappropriate result type of BroadcastChannel which provides send and close operations that interfere with the broadcasting coroutine in hard-to-specify ways.

Note: This API is obsolete since 1.5.0. It will be deprecated with warning in 1.6.0 and with error in 1.7.0. It is replaced with Flow.shareIn operator.

Parameters

start

coroutine start option. The default value is CoroutineStart.LAZY.


fun <E> CoroutineScope.broadcast(    context: CoroutineContext = EmptyCoroutineContext,     capacity: Int = 1,     start: CoroutineStart = CoroutineStart.LAZY,     onCompletion: CompletionHandler? = null,     block: suspend ProducerScope<E>.() -> Unit): BroadcastChannel<E>

Launches new coroutine to produce a stream of values by sending them to a broadcast channel and returns a reference to the coroutine as a BroadcastChannel. The resulting object can be used to subscribe to elements produced by this coroutine.

The scope of the coroutine contains ProducerScope interface, which implements both CoroutineScope and SendChannel, so that coroutine can invoke send directly. The channel is closed when the coroutine completes.

Coroutine context is inherited from a CoroutineScope, additional context elements can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. The parent job is inherited from a CoroutineScope as well, but it can also be overridden with corresponding context element.

Uncaught exceptions in this coroutine close the channel with this exception as a cause and the resulting channel becomes failed, so that any attempt to receive from such a channel throws exception.

The kind of the resulting channel depends on the specified capacity parameter:

Note: By default, the coroutine does not start until the first subscriber appears via BroadcastChannel.openSubscription as start parameter has a value of CoroutineStart.LAZY by default. This ensures that the first subscriber does not miss any sent elements. However, later subscribers may miss elements.

See newCoroutineContext for a description of debugging facilities that are available for newly created coroutine.

Cancelling broadcast

To stop broadcasting from the underlying channel call cancel on the result.

Do not use close on the resulting channel. It causes failure of the send operation in broadcast coroutine and would not cancel it if the coroutine is doing something else.

Future replacement

This API is obsolete since 1.5.0. This function has an inappropriate result type of BroadcastChannel which provides send and close operations that interfere with the broadcasting coroutine in hard-to-specify ways. It will be deprecated with warning in 1.6.0 and with error in 1.7.0. It is replaced with Flow.shareIn operator.

Parameters

context

additional to CoroutineScope.coroutineContext context of the coroutine.

capacity

capacity of the channel's buffer (1 by default).

start

coroutine start option. The default value is CoroutineStart.LAZY.

onCompletion

optional completion handler for the producer coroutine (see Job.invokeOnCompletion).

block

the coroutine code.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/consume-each.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/consume-each.html index 5dae6fe646..6f4c57fc45 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/consume-each.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/consume-each.html @@ -1,83 +1 @@ - - - - - consumeEach - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

consumeEach

-
-
-
-
inline suspend fun <E> ReceiveChannel<E>.consumeEach(action: (E) -> Unit)

Performs the given action for each received element and cancels the channel after the execution of the block. If you need to iterate over the channel without consuming it, a regular for loop should be used instead.

The operation is terminal. This function consumes all elements of the original ReceiveChannel.


inline suspend fun <E> BroadcastChannel<E>.consumeEach(action: (E) -> Unit)

Subscribes to this BroadcastChannel and performs the specified action for each received element.

Note: This API will become obsolete in future updates with introduction of lazy asynchronous streams. See issue #254.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/consume.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/consume.html index 4b8e2f18fb..d198ab08ab 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/consume.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/consume.html @@ -1,83 +1 @@ - - - - - consume - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

consume

-
-
-
-
inline fun <E, R> BroadcastChannel<E>.consume(block: ReceiveChannel<E>.() -> R): R

Opens subscription to this BroadcastChannel and makes sure that the given block consumes all elements from it by always invoking cancel after the execution of the block.

Note: This API will become obsolete in future updates with introduction of lazy asynchronous streams. See issue #254.


inline fun <E, R> ReceiveChannel<E>.consume(block: ReceiveChannel<E>.() -> R): R

Makes sure that the given block consumes all elements from the given channel by always invoking cancel after the execution of the block.

The operation is terminal.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/get-or-else.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/get-or-else.html index 16d8142e23..189b5ae996 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/get-or-else.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/get-or-else.html @@ -1,72 +1 @@ - - - - - getOrElse - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

getOrElse

-
-
-
-
inline fun <T> ChannelResult<T>.getOrElse(onFailure: (exception: Throwable?) -> T): T

Returns the encapsulated value if this instance represents success or the result of onFailure function for the encapsulated Throwable exception if it is failed or closed result.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/index.html index 93f0d8cc5f..929b6eee9c 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/index.html @@ -1,563 +1 @@ - - - - - kotlinx.coroutines.channels - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Package kotlinx.coroutines.channels

-
-
-

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

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

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

-
-
-
-
-

Types

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface ActorScope<E> : CoroutineScope, ReceiveChannel<E>

Scope for actor coroutine builder.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface BroadcastChannel<E> : SendChannel<E>

Broadcast channel is a non-blocking primitive for communication between the sender and multiple receivers that subscribe for the elements using openSubscription function and unsubscribe using ReceiveChannel.cancel function.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
enum BufferOverflow : Enum<BufferOverflow>

A strategy for buffer overflow handling in channels and flows that controls what is going to be sacrificed on buffer overflow:

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface Channel<E> : SendChannel<E> , ReceiveChannel<E>

Channel is a non-blocking primitive for communication between a sender (via SendChannel) and a receiver (via ReceiveChannel). Conceptually, a channel is similar to Java's java.util.concurrent.BlockingQueue, but it has suspending operations instead of blocking ones and can be closed.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface ChannelIterator<out E>

Iterator for ReceiveChannel. Instances of this interface are not thread-safe and shall not be used from concurrent coroutines.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
value class ChannelResult<out T>

A discriminated union of channel operation result. It encapsulates the successful or failed result of a channel operation or a failed operation to a closed channel with an optional cause.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
class ClosedReceiveChannelException(message: String?) : NoSuchElementException

Indicates an attempt to receive from a isClosedForReceive channel that was closed without a cause. A failed channel rethrows the original close cause exception on receive attempts.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
class ClosedSendChannelException(message: String?) : IllegalStateException

Indicates an attempt to send to a isClosedForSend channel that was closed without a cause. A failed channel rethrows the original close cause exception on send attempts.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Broadcasts the most recently sent element (aka value) to all openSubscription subscribers.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface ProducerScope<in E> : CoroutineScope, SendChannel<E>

Scope for the produce, callbackFlow and channelFlow builders.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface ReceiveChannel<out E>

Receiver's interface to Channel.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface SendChannel<in E>

Sender's interface to Channel.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
enum TickerMode : Enum<TickerMode>

Mode for ticker function.

-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <E> CoroutineScope.actor(    context: CoroutineContext = EmptyCoroutineContext,     capacity: Int = 0,     start: CoroutineStart = CoroutineStart.DEFAULT,     onCompletion: CompletionHandler? = null,     block: suspend ActorScope<E>.() -> Unit): SendChannel<E>

Launches new coroutine that is receiving messages from its mailbox channel and returns a reference to its mailbox channel as a SendChannel. The resulting object can be used to send messages to this coroutine.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun ProducerScope<*>.awaitClose(block: () -> Unit = {})

Suspends the current coroutine until the channel is either closed or cancelled and invokes the given block before resuming the coroutine.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <E> ReceiveChannel<E>.broadcast(capacity: Int = 1, start: CoroutineStart = CoroutineStart.LAZY): BroadcastChannel<E>

Broadcasts all elements of the channel. This function consumes all elements of the original ReceiveChannel.

fun <E> CoroutineScope.broadcast(    context: CoroutineContext = EmptyCoroutineContext,     capacity: Int = 1,     start: CoroutineStart = CoroutineStart.LAZY,     onCompletion: CompletionHandler? = null,     block: suspend ProducerScope<E>.() -> Unit): BroadcastChannel<E>

Launches new coroutine to produce a stream of values by sending them to a broadcast channel and returns a reference to the coroutine as a BroadcastChannel. The resulting object can be used to subscribe to elements produced by this coroutine.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <E> BroadcastChannel(capacity: Int): BroadcastChannel<E>

Creates a broadcast channel with the specified buffer capacity.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <E> Channel(capacity: Int = RENDEZVOUS): Channel<E>

fun <E> Channel(    capacity: Int = RENDEZVOUS,     onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND,     onUndeliveredElement: (E) -> Unit? = null): Channel<E>

Creates a channel with the specified buffer capacity (or without a buffer by default). See Channel interface documentation for details.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <E, R> BroadcastChannel<E>.consume(block: ReceiveChannel<E>.() -> R): R

Opens subscription to this BroadcastChannel and makes sure that the given block consumes all elements from it by always invoking cancel after the execution of the block.

inline fun <E, R> ReceiveChannel<E>.consume(block: ReceiveChannel<E>.() -> R): R

Makes sure that the given block consumes all elements from the given channel by always invoking cancel after the execution of the block.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline suspend fun <E> BroadcastChannel<E>.consumeEach(action: (E) -> Unit)

Subscribes to this BroadcastChannel and performs the specified action for each received element.

inline suspend fun <E> ReceiveChannel<E>.consumeEach(action: (E) -> Unit)

Performs the given action for each received element and cancels the channel after the execution of the block. If you need to iterate over the channel without consuming it, a regular for loop should be used instead.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T> ChannelResult<T>.getOrElse(onFailure: (exception: Throwable?) -> T): T

Returns the encapsulated value if this instance represents success or the result of onFailure function for the encapsulated Throwable exception if it is failed or closed result.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T> ChannelResult<T>.onClosed(action: (exception: Throwable?) -> Unit): ChannelResult<T>

Performs the given action on the encapsulated Throwable exception if this instance represents failure due to channel being closed. The result of ChannelResult.exceptionOrNull is passed to the action parameter. It is guaranteed that if action is invoked, then the channel is either closed for send or is closed for receive depending on the failed operation.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T> ChannelResult<T>.onFailure(action: (exception: Throwable?) -> Unit): ChannelResult<T>

Performs the given action on the encapsulated Throwable exception if this instance represents failure. The result of ChannelResult.exceptionOrNull is passed to the action parameter.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <E : Any> ReceiveChannel<E>.onReceiveOrNull(): SelectClause1<E?>

This function is deprecated in the favour of ReceiveChannel.onReceiveCatching

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T> ChannelResult<T>.onSuccess(action: (T) -> Unit): ChannelResult<T>

Performs the given action on the encapsulated value if this instance represents success. Returns the original ChannelResult unchanged.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <E> CoroutineScope.produce(    context: CoroutineContext = EmptyCoroutineContext,     capacity: Int = 0,     block: suspend ProducerScope<E>.() -> Unit): ReceiveChannel<E>

Launches a new coroutine to produce a stream of values by sending them to a channel and returns a reference to the coroutine as a ReceiveChannel. This resulting object can be used to receive elements produced by this coroutine.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun ticker(    delayMillis: Long,     initialDelayMillis: Long = delayMillis,     context: CoroutineContext = EmptyCoroutineContext,     mode: TickerMode = TickerMode.FIXED_PERIOD): ReceiveChannel<Unit>

Creates a channel that produces the first item after the given initial delay and subsequent items with the given delay between them.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <E> ReceiveChannel<E>.toList(): List<E>

Returns a List containing all elements.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <E> SendChannel<E>.trySendBlocking(element: E): ChannelResult<Unit>

Adds element to this channel, blocking the caller while this channel is full, and returning either successful result when the element was added, or failed result representing closed channel with a corresponding exception.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/on-closed.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/on-closed.html index cc69de6884..2ff29043bd 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/on-closed.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/on-closed.html @@ -1,72 +1 @@ - - - - - onClosed - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

onClosed

-
-
-
-
inline fun <T> ChannelResult<T>.onClosed(action: (exception: Throwable?) -> Unit): ChannelResult<T>

Performs the given action on the encapsulated Throwable exception if this instance represents failure due to channel being closed. The result of ChannelResult.exceptionOrNull is passed to the action parameter. It is guaranteed that if action is invoked, then the channel is either closed for send or is closed for receive depending on the failed operation.

Returns the original ChannelResult unchanged.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/on-failure.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/on-failure.html index b5213afe4a..a8d1316832 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/on-failure.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/on-failure.html @@ -1,72 +1 @@ - - - - - onFailure - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

onFailure

-
-
-
-
inline fun <T> ChannelResult<T>.onFailure(action: (exception: Throwable?) -> Unit): ChannelResult<T>

Performs the given action on the encapsulated Throwable exception if this instance represents failure. The result of ChannelResult.exceptionOrNull is passed to the action parameter.

Returns the original ChannelResult unchanged.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/on-receive-or-null.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/on-receive-or-null.html index 1ea1055da6..84c0276e8e 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/on-receive-or-null.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/on-receive-or-null.html @@ -1,72 +1 @@ - - - - - onReceiveOrNull - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

onReceiveOrNull

-
-
-
-
fun <E : Any> ReceiveChannel<E>.onReceiveOrNull(): SelectClause1<E?>

This function is deprecated in the favour of ReceiveChannel.onReceiveCatching

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/on-success.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/on-success.html index 1d68c279f6..5605de339b 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/on-success.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/on-success.html @@ -1,72 +1 @@ - - - - - onSuccess - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

onSuccess

-
-
-
-
inline fun <T> ChannelResult<T>.onSuccess(action: (T) -> Unit): ChannelResult<T>

Performs the given action on the encapsulated value if this instance represents success. Returns the original ChannelResult unchanged.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/produce.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/produce.html index 9666096ab7..7496c91f09 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/produce.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/produce.html @@ -1,72 +1 @@ - - - - - produce - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

produce

-
-
-
-
fun <E> CoroutineScope.produce(    context: CoroutineContext = EmptyCoroutineContext,     capacity: Int = 0,     block: suspend ProducerScope<E>.() -> Unit): ReceiveChannel<E>

Launches a new coroutine to produce a stream of values by sending them to a channel and returns a reference to the coroutine as a ReceiveChannel. This resulting object can be used to receive elements produced by this coroutine.

The scope of the coroutine contains the ProducerScope interface, which implements both CoroutineScope and SendChannel, so that the coroutine can invoke send directly. The channel is closed when the coroutine completes. The running coroutine is cancelled when its receive channel is cancelled.

The coroutine context is inherited from this CoroutineScope. Additional context elements can be specified with the context argument. If the context does not have any dispatcher or other ContinuationInterceptor, then Dispatchers.Default is used. The parent job is inherited from the CoroutineScope as well, but it can also be overridden with a corresponding context element.

Any uncaught exception in this coroutine will close the channel with this exception as the cause and the resulting channel will become failed, so that any attempt to receive from it thereafter will throw an exception.

The kind of the resulting channel depends on the specified capacity parameter. See the Channel interface documentation for details.

See newCoroutineContext for a description of debugging facilities available for newly created coroutines.

Note: This is an experimental api. Behaviour of producers that work as children in a parent scope with respect to cancellation and error handling may change in the future.

Parameters

context

additional to CoroutineScope.coroutineContext context of the coroutine.

capacity

capacity of the channel's buffer (no buffer by default).

block

the coroutine code.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/ticker.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/ticker.html index a333115d55..b704b75258 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/ticker.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/ticker.html @@ -1,72 +1 @@ - - - - - ticker - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

ticker

-
-
-
-
fun ticker(    delayMillis: Long,     initialDelayMillis: Long = delayMillis,     context: CoroutineContext = EmptyCoroutineContext,     mode: TickerMode = TickerMode.FIXED_PERIOD): ReceiveChannel<Unit>

Creates a channel that produces the first item after the given initial delay and subsequent items with the given delay between them.

The resulting channel is a rendezvous channel. When receiver from this channel does not keep up with receiving the elements from this channel, they are not being sent due to backpressure. The actual timing behavior of ticker in this case is controlled by mode parameter which is set to TickerMode.FIXED_PERIOD by default. See TickerMode for other details.

This channel stops producing elements immediately after ReceiveChannel.cancel invocation.

Note producer to this channel is dispatched via Dispatchers.Unconfined by default and started eagerly.

Note: Ticker channels are not currently integrated with structured concurrency and their api will change in the future.

Parameters

delayMillis

delay between each element in milliseconds.

initialDelayMillis

delay after which the first element will be produced (it is equal to delayMillis by default) in milliseconds.

context

context of the producing coroutine.

mode

specifies behavior when elements are not received (FIXED_PERIOD by default).

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/to-list.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/to-list.html index a8991a8831..6a1ce89543 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/to-list.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/to-list.html @@ -1,72 +1 @@ - - - - - toList - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

toList

-
-
-
-
suspend fun <E> ReceiveChannel<E>.toList(): List<E>

Returns a List containing all elements.

The operation is terminal. This function consumes all elements of the original ReceiveChannel.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.channels/try-send-blocking.html b/kotlinx-coroutines-core/kotlinx.coroutines.channels/try-send-blocking.html index a664c10e1a..ded1fac075 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.channels/try-send-blocking.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.channels/try-send-blocking.html @@ -1,59 +1 @@ - - - - - trySendBlocking - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

trySendBlocking

-
-
-
-
fun <E> SendChannel<E>.trySendBlocking(element: E): ChannelResult<Unit>

Adds element to this channel, blocking the caller while this channel is full, and returning either successful result when the element was added, or failed result representing closed channel with a corresponding exception.

This is a way to call Channel.send method in a safe manner inside a blocking code using runBlocking and catching, so this function should not be used from coroutine.

Example of usage:

// From callback API
channel.trySendBlocking(element)
.onSuccess { /* request next element or debug log */}
.onFailure { t: Throwable? -> /* throw or log */}

For this operation it is guaranteed that failure always contains an exception in it.

Throws

InterruptedException on JVM if the current thread is interrupted during the blocking send operation.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-abstract-flow/-abstract-flow.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-abstract-flow/-abstract-flow.html index 0b3739c633..bd8431a116 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-abstract-flow/-abstract-flow.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-abstract-flow/-abstract-flow.html @@ -1,72 +1 @@ - - - - - AbstractFlow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

AbstractFlow

-
-
-
-
fun AbstractFlow()
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-abstract-flow/collect-safely.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-abstract-flow/collect-safely.html index f45e7e3611..0d49867586 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-abstract-flow/collect-safely.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-abstract-flow/collect-safely.html @@ -1,72 +1 @@ - - - - - collectSafely - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

collectSafely

-
-
-
-
abstract suspend fun collectSafely(collector: FlowCollector<T>)

Accepts the given collector and emits values into it.

A valid implementation of this method has the following constraints:

  1. It should not change the coroutine context (e.g. with withContext(Dispatchers.IO)) when emitting values. The emission should happen in the context of the collect call. Please refer to the top-level Flow documentation for more details.

  2. It should serialize calls to emit as FlowCollector implementations are not thread-safe by default. To automatically serialize emissions channelFlow builder can be used instead of flow

Throws

if any of the invariants are violated.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-abstract-flow/collect.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-abstract-flow/collect.html index aee53ec91b..c32c60c478 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-abstract-flow/collect.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-abstract-flow/collect.html @@ -1,72 +1 @@ - - - - - collect - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

collect

-
-
-
-
suspend override fun collect(collector: FlowCollector<T>)

Accepts the given collector and emits values into it.

This method can be used along with SAM-conversion of FlowCollector:

myFlow.collect { value -> println("Collected $value") }

Method inheritance

To ensure the context preservation property, it is not recommended implementing this method directly. Instead, AbstractFlow can be used as the base type to properly ensure flow's properties.

All default flow implementations ensure context preservation and exception transparency properties on a best-effort basis and throw IllegalStateException if a violation was detected.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-abstract-flow/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-abstract-flow/index.html index 92acb437fd..8ea30896e7 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-abstract-flow/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-abstract-flow/index.html @@ -1,132 +1 @@ - - - - - AbstractFlow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

AbstractFlow

-
-
-
abstract class AbstractFlow<T> : Flow<T> , CancellableFlow<T>

Base class for stateful implementations of Flow. It tracks all the properties required for context preservation and throws an IllegalStateException if any of the properties are violated.

Example of the implementation:

// list.asFlow() + collect counter
class CountingListFlow(private val values: List<Int>) : AbstractFlow<Int>() {
private val collectedCounter = AtomicInteger(0)

override suspend fun collectSafely(collector: FlowCollector<Int>) {
collectedCounter.incrementAndGet() // Increment collected counter
values.forEach { // Emit all the values
collector.emit(it)
}
}

fun toDiagnosticString(): String = "Flow with values $values was collected ${collectedCounter.value} times"
}
-
-
-
-
-

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun AbstractFlow()
-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend override fun collect(collector: FlowCollector<T>)

Accepts the given collector and emits values into it.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract suspend fun collectSafely(collector: FlowCollector<T>)

Accepts the given collector and emits values into it.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-d-e-f-a-u-l-t_-c-o-n-c-u-r-r-e-n-c-y.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-d-e-f-a-u-l-t_-c-o-n-c-u-r-r-e-n-c-y.html index b4226faa32..f3b6d13b27 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-d-e-f-a-u-l-t_-c-o-n-c-u-r-r-e-n-c-y.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-d-e-f-a-u-l-t_-c-o-n-c-u-r-r-e-n-c-y.html @@ -1,72 +1 @@ - - - - - DEFAULT_CONCURRENCY - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

DEFAULT_CONCURRENCY

-
-
-
-
val DEFAULT_CONCURRENCY: Int

Default concurrency limit that is used by flattenMerge and flatMapMerge operators. It is 16 by default and can be changed on JVM using DEFAULT_CONCURRENCY_PROPERTY_NAME property.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-d-e-f-a-u-l-t_-c-o-n-c-u-r-r-e-n-c-y_-p-r-o-p-e-r-t-y_-n-a-m-e.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-d-e-f-a-u-l-t_-c-o-n-c-u-r-r-e-n-c-y_-p-r-o-p-e-r-t-y_-n-a-m-e.html index 0498b34f03..3fe7fa7f52 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-d-e-f-a-u-l-t_-c-o-n-c-u-r-r-e-n-c-y_-p-r-o-p-e-r-t-y_-n-a-m-e.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-d-e-f-a-u-l-t_-c-o-n-c-u-r-r-e-n-c-y_-p-r-o-p-e-r-t-y_-n-a-m-e.html @@ -1,72 +1 @@ - - - - - DEFAULT_CONCURRENCY_PROPERTY_NAME - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

DEFAULT_CONCURRENCY_PROPERTY_NAME

-
-
-
-
const val DEFAULT_CONCURRENCY_PROPERTY_NAME: String

Name of the property that defines the value of DEFAULT_CONCURRENCY.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow-collector/emit.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow-collector/emit.html index 5af06c07ce..ea6a312878 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow-collector/emit.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow-collector/emit.html @@ -1,72 +1 @@ - - - - - emit - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

emit

-
-
-
-
abstract suspend fun emit(value: T)

Collects the value emitted by the upstream. This method is not thread-safe and should not be invoked concurrently.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow-collector/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow-collector/index.html index 33c4935586..069cf3b6c4 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow-collector/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow-collector/index.html @@ -1,128 +1 @@ - - - - - FlowCollector - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

FlowCollector

-
-
-
fun interface FlowCollector<in T>

FlowCollector is used as an intermediate or a terminal collector of the flow and represents an entity that accepts values emitted by the Flow.

This interface should usually not be implemented directly, but rather used as a receiver in a flow builder when implementing a custom operator, or with SAM-conversion. Implementations of this interface are not thread-safe.

Example of usage:

val flow = getMyEvents()
try {
flow.collect { value ->
println("Received $value")
}
println("My events are consumed successfully")
} catch (e: Throwable) {
println("Exception from the flow: $e")
}
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract suspend fun emit(value: T)

Collects the value emitted by the upstream. This method is not thread-safe and should not be invoked concurrently.

-
-
-
-
-
-

Inheritors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Extensions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> FlowCollector<T>.emitAll(channel: ReceiveChannel<T>)

Emits all elements from the given channel to this flow collector and cancels (consumes) the channel afterwards. If you need to iterate over the channel without consuming it, a regular for loop should be used instead.

suspend fun <T> FlowCollector<T>.emitAll(flow: Flow<T>)

Collects all the values from the given flow and emits them to the collector. It is a shorthand for flow.collect { value -> emit(value) }.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/collect.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/collect.html index 3c27216b4f..4b687b4e51 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/collect.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/collect.html @@ -1,72 +1 @@ - - - - - collect - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

collect

-
-
-
-
abstract suspend fun collect(collector: FlowCollector<T>)

Accepts the given collector and emits values into it.

This method can be used along with SAM-conversion of FlowCollector:

myFlow.collect { value -> println("Collected $value") }

Method inheritance

To ensure the context preservation property, it is not recommended implementing this method directly. Instead, AbstractFlow can be used as the base type to properly ensure flow's properties.

All default flow implementations ensure context preservation and exception transparency properties on a best-effort basis and throw IllegalStateException if a violation was detected.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html index 65a8db44fd..f361cf7e37 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html @@ -1,1142 +1 @@ - - - - - Flow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Flow

-
-
-
interface Flow<out T>

An asynchronous data stream that sequentially emits values and completes normally or with an exception.

Intermediate operators on the flow such as map, filter, take, zip, etc are functions that are applied to the upstream flow or flows and return a downstream flow where further operators can be applied to. Intermediate operations do not execute any code in the flow and are not suspending functions themselves. They only set up a chain of operations for future execution and quickly return. This is known as a cold flow property.

Terminal operators on the flow are either suspending functions such as collect, single, reduce, toList, etc. or launchIn operator that starts collection of the flow in the given scope. They are applied to the upstream flow and trigger execution of all operations. Execution of the flow is also called collecting the flow and is always performed in a suspending manner without actual blocking. Terminal operators complete normally or exceptionally depending on successful or failed execution of all the flow operations in the upstream. The most basic terminal operator is collect, for example:

try {
flow.collect { value ->
println("Received $value")
}
} catch (e: Exception) {
println("The flow has thrown an exception: $e")
}

By default, flows are sequential and all flow operations are executed sequentially in the same coroutine, with an exception for a few operations specifically designed to introduce concurrency into flow execution such as buffer and flatMapMerge. See their documentation for details.

The Flow interface does not carry information whether a flow is a cold stream that can be collected repeatedly and triggers execution of the same code every time it is collected, or if it is a hot stream that emits different values from the same running source on each collection. Usually flows represent cold streams, but there is a SharedFlow subtype that represents hot streams. In addition to that, any flow can be turned into a hot one by the stateIn and shareIn operators, or by converting the flow into a hot channel via the produceIn operator.

Flow builders

There are the following basic ways to create a flow:

  • flowOf(...) functions to create a flow from a fixed set of values.

  • asFlow() extension functions on various types to convert them into flows.

  • flow { ... } builder function to construct arbitrary flows from sequential calls to emit function.

  • channelFlow { ... } builder function to construct arbitrary flows from potentially concurrent calls to the send function.

  • MutableStateFlow and MutableSharedFlow define the corresponding constructor functions to create a hot flow that can be directly updated.

Flow constraints

All implementations of the Flow interface must adhere to two key properties described in detail below:

  • Context preservation.

  • Exception transparency.

These properties ensure the ability to perform local reasoning about the code with flows and modularize the code in such a way that upstream flow emitters can be developed separately from downstream flow collectors. A user of a flow does not need to be aware of implementation details of the upstream flows it uses.

Context preservation

The flow has a context preservation property: it encapsulates its own execution context and never propagates or leaks it downstream, thus making reasoning about the execution context of particular transformations or terminal operations trivial.

There is only one way to change the context of a flow: the flowOn operator that changes the upstream context ("everything above the flowOn operator"). For additional information refer to its documentation.

This reasoning can be demonstrated in practice:

val flowA = flowOf(1, 2, 3)
.map { it + 1 } // Will be executed in ctxA
.flowOn(ctxA) // Changes the upstream context: flowOf and map

// Now we have a context-preserving flow: it is executed somewhere but this information is encapsulated in the flow itself

val filtered = flowA // ctxA is encapsulated in flowA
.filter { it == 3 } // Pure operator without a context yet

withContext(Dispatchers.Main) {
// All non-encapsulated operators will be executed in Main: filter and single
val result = filtered.single()
myUi.text = result
}

From the implementation point of view, it means that all flow implementations should only emit from the same coroutine. This constraint is efficiently enforced by the default flow builder. The flow builder should be used if the flow implementation does not start any coroutines. Its implementation prevents most of the development mistakes:

val myFlow = flow {
// GlobalScope.launch { // is prohibited
// launch(Dispatchers.IO) { // is prohibited
// withContext(CoroutineName("myFlow")) { // is prohibited
emit(1) // OK
coroutineScope {
emit(2) // OK -- still the same coroutine
}
}

Use channelFlow if the collection and emission of a flow are to be separated into multiple coroutines. It encapsulates all the context preservation work and allows you to focus on your domain-specific problem, rather than invariant implementation details. It is possible to use any combination of coroutine builders from within channelFlow.

If you are looking for performance and are sure that no concurrent emits and context jumps will happen, the flow builder can be used alongside a coroutineScope or supervisorScope instead:

  • Scoped primitive should be used to provide a CoroutineScope.

  • Changing the context of emission is prohibited, no matter whether it is withContext(ctx) or a builder argument (e.g. launch(ctx)).

  • Collecting another flow from a separate context is allowed, but it has the same effect as applying the flowOn operator to that flow, which is more efficient.

Exception transparency

When emit or emitAll throws, the Flow implementations must immediately stop emitting new values and finish with an exception. For diagnostics or application-specific purposes, the exception may be different from the one thrown by the emit operation, suppressing the original exception as discussed below. If there is a need to emit values after the downstream failed, please use the catch operator.

The catch operator only catches upstream exceptions, but passes all downstream exceptions. Similarly, terminal operators like collect throw any unhandled exceptions that occur in their code or in upstream flows, for example:

flow { emitData() }
.map { computeOne(it) }
.catch { ... } // catches exceptions in emitData and computeOne
.map { computeTwo(it) }
.collect { process(it) } // throws exceptions from process and computeTwo

The same reasoning can be applied to the onCompletion operator that is a declarative replacement for the finally block.

All exception-handling Flow operators follow the principle of exception suppression:

If the upstream flow throws an exception during its completion when the downstream exception has been thrown, the downstream exception becomes superseded and suppressed by the upstream exception, being a semantic equivalent of throwing from finally block. However, this doesn't affect the operation of the exception-handling operators, which consider the downstream exception to be the root cause and behave as if the upstream didn't throw anything.

Failure to adhere to the exception transparency requirement can lead to strange behaviors which make it hard to reason about the code because an exception in the collect { ... } could be somehow "caught" by an upstream flow, limiting the ability of local reasoning about the code.

Flow machinery enforces exception transparency at runtime and throws IllegalStateException on any attempt to emit a value, if an exception has been thrown on previous attempt.

Reactive streams

Flow is Reactive Streams compliant, you can safely interop it with reactive streams using Flow.asPublisher and Publisher.asFlow from kotlinx-coroutines-reactive module.

Not stable for inheritance

The Flow interface is not stable for inheritance in 3rd party libraries, as new methods might be added to this interface in the future, but is stable for use.

Use the flow { ... } builder function to create an implementation, or extend AbstractFlow. These implementations ensure that the context preservation property is not violated, and prevent most of the developer mistakes related to concurrency, inconsistent flow dispatchers, and cancellation.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract suspend fun collect(collector: FlowCollector<T>)

Accepts the given collector and emits values into it.

-
-
-
-
-
-

Inheritors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Extensions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.buffer(capacity: Int = BUFFERED, onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND): Flow<T>

Buffers flow emissions via channel of a specified capacity and runs collector in a separate coroutine.

fun <T> Flow<T>.buffer(capacity: Int = BUFFERED): Flow<T>
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.cancellable(): Flow<T>

Returns a flow which checks cancellation status on each emission and throws the corresponding cancellation cause if flow collector was cancelled. Note that flow builder and all implementations of SharedFlow are cancellable by default.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.catch(action: suspend FlowCollector<T>.(cause: Throwable) -> Unit): Flow<T>

Catches exceptions in the flow completion and calls a specified action with the caught exception. This operator is transparent to exceptions that occur in downstream flow and does not catch exceptions that are thrown to cancel the flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun Flow<*>.collect()

Terminal flow operator that collects the given flow but ignores all emitted values. If any exception occurs during collect or in the provided flow, this exception is rethrown from this method.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline suspend fun <T> Flow<T>.collectIndexed(crossinline action: suspend (index: Int, T) -> Unit)

Terminal flow operator that collects the given flow with a provided action that takes the index of an element (zero-based) and the element. If any exception occurs during collect or in the provided flow, this exception is rethrown from this method.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> Flow<T>.collectLatest(action: suspend (T) -> Unit)

Terminal flow operator that collects the given flow with a provided action. The crucial difference from collect is that when the original flow emits a new value then the action block for the previous value is cancelled.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
@JvmName(name = "flowCombine")
fun <T1, T2, R> Flow<T1>.combine(flow: Flow<T2>, transform: suspend (T1, T2) -> R): Flow<R>

Returns a Flow whose values are generated with transform function by combining the most recently emitted values by each flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
@JvmName(name = "flowCombineTransform")
fun <T1, T2, R> Flow<T1>.combineTransform(flow: Flow<T2>, transform: suspend FlowCollector<R>.(T1, T2) -> Unit): Flow<R>

Returns a Flow whose values are generated by transform function that process the most recently emitted values by each flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.conflate(): Flow<T>

Conflates flow emissions via conflated channel and runs collector in a separate coroutine. The effect of this is that emitter is never suspended due to a slow collector, but collector always gets the most recent value emitted.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> Flow<T>.count(): Int

Returns the number of elements in this flow.

suspend fun <T> Flow<T>.count(predicate: suspend (T) -> Boolean): Int

Returns the number of elements matching the given predicate.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.debounce(timeoutMillis: Long): Flow<T>
fun <T> Flow<T>.debounce(timeoutMillis: (T) -> Long): Flow<T>
fun <T> Flow<T>.debounce(timeout: Duration): Flow<T>
@JvmName(name = "debounceDuration")
fun <T> Flow<T>.debounce(timeout: (T) -> Duration): Flow<T>

Returns a flow that mirrors the original flow, but filters out values that are followed by the newer values within the given timeout. The latest value is always emitted.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.distinctUntilChanged(): Flow<T>

Returns flow where all subsequent repetitions of the same value are filtered out.

fun <T> Flow<T>.distinctUntilChanged(areEquivalent: (T, T) -> Boolean): Flow<T>

Returns flow where all subsequent repetitions of the same value are filtered out, when compared with each other via the provided areEquivalent function.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T, K> Flow<T>.distinctUntilChangedBy(keySelector: (T) -> K): Flow<T>

Returns flow where all subsequent repetitions of the same key are filtered out, where key is extracted with keySelector function.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.drop(count: Int): Flow<T>

Returns a flow that ignores first count elements. Throws IllegalArgumentException if count is negative.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.dropWhile(predicate: suspend (T) -> Boolean): Flow<T>

Returns a flow containing all elements except first elements that satisfy the given predicate.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T> Flow<T>.filter(crossinline predicate: suspend (T) -> Boolean): Flow<T>

Returns a flow containing only values of the original flow that match the given predicate.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <R> Flow<*>.filterIsInstance(): Flow<R>

Returns a flow containing only values that are instances of specified type R.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T> Flow<T>.filterNot(crossinline predicate: suspend (T) -> Boolean): Flow<T>

Returns a flow containing only values of the original flow that do not match the given predicate.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T : Any> Flow<T?>.filterNotNull(): Flow<T>

Returns a flow containing only values of the original flow that are not null.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> Flow<T>.first(): T

The terminal operator that returns the first element emitted by the flow and then cancels flow's collection. Throws NoSuchElementException if the flow was empty.

suspend fun <T> Flow<T>.first(predicate: suspend (T) -> Boolean): T

The terminal operator that returns the first element emitted by the flow matching the given predicate and then cancels flow's collection. Throws NoSuchElementException if the flow has not contained elements matching the predicate.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> Flow<T>.firstOrNull(): T?

The terminal operator that returns the first element emitted by the flow and then cancels flow's collection. Returns null if the flow was empty.

suspend fun <T> Flow<T>.firstOrNull(predicate: suspend (T) -> Boolean): T?

The terminal operator that returns the first element emitted by the flow matching the given predicate and then cancels flow's collection. Returns null if the flow did not contain an element matching the predicate.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T, R> Flow<T>.flatMapConcat(transform: suspend (T) -> Flow<R>): Flow<R>

Transforms elements emitted by the original flow by applying transform, that returns another flow, and then concatenating and flattening these flows.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T, R> Flow<T>.flatMapLatest(crossinline transform: suspend (T) -> Flow<R>): Flow<R>

Returns a flow that switches to a new flow produced by transform function every time the original flow emits a value. When the original flow emits a new value, the previous flow produced by transform block is cancelled.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T, R> Flow<T>.flatMapMerge(concurrency: Int = DEFAULT_CONCURRENCY, transform: suspend (T) -> Flow<R>): Flow<R>

Transforms elements emitted by the original flow by applying transform, that returns another flow, and then merging and flattening these flows.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<Flow<T>>.flattenConcat(): Flow<T>

Flattens the given flow of flows into a single flow in a sequential manner, without interleaving nested flows.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<Flow<T>>.flattenMerge(concurrency: Int = DEFAULT_CONCURRENCY): Flow<T>

Flattens the given flow of flows into a single flow with a concurrency limit on the number of concurrently collected flows.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.flowOn(context: CoroutineContext): Flow<T>

Changes the context where this flow is executed to the given context. This operator is composable and affects only preceding operators that do not have its own context. This operator is context preserving: contextdoes not leak into the downstream flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline suspend fun <T, R> Flow<T>.fold(initial: R, crossinline operation: suspend (R, T) -> R): R

Accumulates value starting with initial value and applying operation current accumulator value and each element

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> Flow<T>.last(): T

The terminal operator that returns the last element emitted by the flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> Flow<T>.lastOrNull(): T?

The terminal operator that returns the last element emitted by the flow or null if the flow was empty.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.launchIn(scope: CoroutineScope): Job

Terminal flow operator that launches the collection of the given flow in the scope. It is a shorthand for scope.launch { flow.collect() }.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T, R> Flow<T>.map(crossinline transform: suspend (T) -> R): Flow<R>

Returns a flow containing the results of applying the given transform function to each value of the original flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T, R> Flow<T>.mapLatest(transform: suspend (T) -> R): Flow<R>

Returns a flow that emits elements from the original flow transformed by transform function. When the original flow emits a new value, computation of the transform block for previous value is cancelled.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T, R : Any> Flow<T>.mapNotNull(crossinline transform: suspend (T) -> R?): Flow<R>

Returns a flow that contains only non-null results of applying the given transform function to each value of the original flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.onCompletion(action: suspend FlowCollector<T>.(cause: Throwable?) -> Unit): Flow<T>

Returns a flow that invokes the given actionafter the flow is completed or cancelled, passing the cancellation exception or failure as cause parameter of action.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.onEach(action: suspend (T) -> Unit): Flow<T>

Returns a flow that invokes the given actionbefore each value of the upstream flow is emitted downstream.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.onEmpty(action: suspend FlowCollector<T>.() -> Unit): Flow<T>

Invokes the given action when this flow completes without emitting any elements. The receiver of the action is FlowCollector, so onEmpty can emit additional elements. For example:

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.onStart(action: suspend FlowCollector<T>.() -> Unit): Flow<T>

Returns a flow that invokes the given actionbefore this flow starts to be collected.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.produceIn(scope: CoroutineScope): ReceiveChannel<T>

Creates a produce coroutine that collects the given flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <S, T : S> Flow<T>.reduce(operation: suspend (S, T) -> S): S

Accumulates value starting with the first element and applying operation to current accumulator value and each element. Throws NoSuchElementException if flow was empty.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.retry(retries: Long = Long.MAX_VALUE, predicate: suspend (cause: Throwable) -> Boolean = { true }): Flow<T>

Retries collection of the given flow up to retries times when an exception that matches the given predicate occurs in the upstream flow. This operator is transparent to exceptions that occur in downstream flow and does not retry on exceptions that are thrown to cancel the flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.retryWhen(predicate: suspend FlowCollector<T>.(cause: Throwable, attempt: Long) -> Boolean): Flow<T>

Retries collection of the given flow when an exception occurs in the upstream flow and the predicate returns true. The predicate also receives an attempt number as parameter, starting from zero on the initial call. This operator is transparent to exceptions that occur in downstream flow and does not retry on exceptions that are thrown to cancel the flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T, R> Flow<T>.runningFold(initial: R, operation: suspend (R, T) -> R): Flow<R>

Folds the given flow with operation, emitting every intermediate result, including initial value. Note that initial value should be immutable (or should not be mutated) as it is shared between different collectors. For example:

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.runningReduce(operation: suspend (T, T) -> T): Flow<T>

Reduces the given flow with operation, emitting every intermediate result, including initial value. The first element is taken as initial value for operation accumulator. This operator has a sibling with initial value -- scan.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.sample(periodMillis: Long): Flow<T>
fun <T> Flow<T>.sample(period: Duration): Flow<T>

Returns a flow that emits only the latest value emitted by the original flow during the given sampling period.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T, R> Flow<T>.scan(initial: R, operation: suspend (R, T) -> R): Flow<R>

Folds the given flow with operation, emitting every intermediate result, including initial value. Note that initial value should be immutable (or should not be mutated) as it is shared between different collectors. For example:

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.shareIn(    scope: CoroutineScope,     started: SharingStarted,     replay: Int = 0): SharedFlow<T>

Converts a coldFlow into a hotSharedFlow that is started in the given coroutine scope, sharing emissions from a single running instance of the upstream flow with multiple downstream subscribers, and replaying a specified number of replay values to new subscribers. See the SharedFlow documentation for the general concepts of shared flows.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> Flow<T>.single(): T

The terminal operator that awaits for one and only one value to be emitted. Throws NoSuchElementException for empty flow and IllegalStateException for flow that contains more than one element.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> Flow<T>.singleOrNull(): T?

The terminal operator that awaits for one and only one value to be emitted. Returns the single value or null, if the flow was empty or emitted more than one value.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.stateIn(    scope: CoroutineScope,     started: SharingStarted,     initialValue: T): StateFlow<T>

Converts a coldFlow into a hotStateFlow that is started in the given coroutine scope, sharing the most recently emitted value from a single running instance of the upstream flow with multiple downstream subscribers. See the StateFlow documentation for the general concepts of state flows.

suspend fun <T> Flow<T>.stateIn(scope: CoroutineScope): StateFlow<T>

Starts the upstream flow in a given scope, suspends until the first value is emitted, and returns a hotStateFlow of future emissions, sharing the most recently emitted value from this running instance of the upstream flow with multiple downstream subscribers. See the StateFlow documentation for the general concepts of state flows.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.take(count: Int): Flow<T>

Returns a flow that contains first count elements. When count elements are consumed, the original flow is cancelled. Throws IllegalArgumentException if count is not positive.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.takeWhile(predicate: suspend (T) -> Boolean): Flow<T>

Returns a flow that contains first elements satisfying the given predicate.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T, C : MutableCollection<in T>> Flow<T>.toCollection(destination: C): C

Collects given flow into a destination

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> Flow<T>.toList(destination: MutableList<T> = ArrayList()): List<T>

Collects given flow into a destination

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> Flow<T>.toSet(destination: MutableSet<T> = LinkedHashSet()): Set<T>

Collects given flow into a destination

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T, R> Flow<T>.transform(crossinline transform: suspend FlowCollector<R>.(T) -> Unit): Flow<R>

Applies transform function to each value of the given flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T, R> Flow<T>.transformLatest(transform: suspend FlowCollector<R>.(T) -> Unit): Flow<R>

Returns a flow that produces element by transform function every time the original flow emits a value. When the original flow emits a new value, the previous transform block is cancelled, thus the name transformLatest.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T, R> Flow<T>.transformWhile(transform: suspend FlowCollector<R>.(T) -> Boolean): Flow<R>

Applies transform function to each value of the given flow while this function returns true.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.withIndex(): Flow<IndexedValue<T>>

Returns a flow that wraps each element into IndexedValue, containing value and its index (starting from zero).

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T1, T2, R> Flow<T1>.zip(other: Flow<T2>, transform: suspend (T1, T2) -> R): Flow<R>

Zips values from the current flow (this) with other flow using provided transform function applied to each pair of values. The resulting flow completes as soon as one of the flows completes and cancel is called on the remaining flow.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow.html index eebd069a27..50bbeba864 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow.html @@ -1,72 +1 @@ - - - - - MutableSharedFlow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

MutableSharedFlow

-
-
-
-
fun <T> MutableSharedFlow(    replay: Int = 0,     extraBufferCapacity: Int = 0,     onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND): MutableSharedFlow<T>

Creates a MutableSharedFlow with the given configuration parameters.

This function throws IllegalArgumentException on unsupported values of parameters or combinations thereof.

Parameters

replay

the number of values replayed to new subscribers (cannot be negative, defaults to zero).

extraBufferCapacity

the number of values buffered in addition to replay. emit does not suspend while there is a buffer space remaining (optional, cannot be negative, defaults to zero).

onBufferOverflow

configures an emit action on buffer overflow. Optional, defaults to suspending attempts to emit a value. Values other than BufferOverflow.SUSPEND are supported only when replay > 0 or extraBufferCapacity > 0. Buffer overflow can happen only when there is at least one subscriber that is not ready to accept the new value. In the absence of subscribers only the most recent replay values are stored and the buffer overflow behavior is never triggered and has no effect.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow/emit.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow/emit.html index 22c72d6b33..3fd5cb043f 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow/emit.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow/emit.html @@ -1,72 +1 @@ - - - - - emit - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

emit

-
-
-
-
abstract suspend override fun emit(value: T)

Emits a value to this shared flow, suspending on buffer overflow.

This call can suspend only when the BufferOverflow strategy is SUSPENDand there are subscribers collecting this shared flow.

If there are no subscribers, the buffer is not used. Instead, the most recently emitted value is simply stored into the replay cache if one was configured, displacing the older elements there, or dropped if no replay cache was configured.

See tryEmit for a non-suspending variant of this function.

This method is thread-safe and can be safely invoked from concurrent coroutines without external synchronization.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow/index.html index 705a7448d2..f5c416f314 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow/index.html @@ -1,181 +1 @@ - - - - - MutableSharedFlow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

MutableSharedFlow

-
-
-
interface MutableSharedFlow<T> : SharedFlow<T> , FlowCollector<T>

A mutable SharedFlow that provides functions to emit values to the flow. An instance of MutableSharedFlow with the given configuration parameters can be created using MutableSharedFlow(...) constructor function.

See the SharedFlow documentation for details on shared flows.

MutableSharedFlow is a SharedFlow that also provides the abilities to emit a value, to tryEmit without suspension if possible, to track the subscriptionCount, and to resetReplayCache.

Concurrency

All methods of shared flow are thread-safe and can be safely invoked from concurrent coroutines without external synchronization.

Not stable for inheritance

The MutableSharedFlow interface is not stable for inheritance in 3rd party libraries, as new methods might be added to this interface in the future, but is stable for use. Use the MutableSharedFlow(...) constructor function to create an implementation.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract suspend override fun emit(value: T)

Emits a value to this shared flow, suspending on buffer overflow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun resetReplayCache()

Resets the replayCache of this shared flow to an empty state. New subscribers will be receiving only the values that were emitted after this call, while old subscribers will still be receiving previously buffered values. To reset a shared flow to an initial value, emit the value after this call.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun tryEmit(value: T): Boolean

Tries to emit a value to this shared flow without suspending. It returns true if the value was emitted successfully (see below). When this function returns false, it means that a call to a plain emit function would suspend until there is buffer space available.

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val subscriptionCount: StateFlow<Int>

The number of subscribers (active collectors) to this shared flow.

-
-
-
-
-
-

Inheritors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Extensions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> MutableSharedFlow<T>.asSharedFlow(): SharedFlow<T>

Represents this mutable shared flow as a read-only shared flow.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow/reset-replay-cache.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow/reset-replay-cache.html index f32df026bb..d7f39e1938 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow/reset-replay-cache.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow/reset-replay-cache.html @@ -1,72 +1 @@ - - - - - resetReplayCache - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

resetReplayCache

-
-
-
-
abstract fun resetReplayCache()

Resets the replayCache of this shared flow to an empty state. New subscribers will be receiving only the values that were emitted after this call, while old subscribers will still be receiving previously buffered values. To reset a shared flow to an initial value, emit the value after this call.

On a MutableStateFlow, which always contains a single value, this function is not supported, and throws an UnsupportedOperationException. To reset a MutableStateFlow to an initial value, just update its value.

This method is thread-safe and can be safely invoked from concurrent coroutines without external synchronization.

Note: This is an experimental api. This function may be removed or renamed in the future.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow/subscription-count.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow/subscription-count.html index 4c34d7d011..95eceeecb2 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow/subscription-count.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow/subscription-count.html @@ -1,72 +1 @@ - - - - - subscriptionCount - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

subscriptionCount

-
-
-
-
abstract val subscriptionCount: StateFlow<Int>

The number of subscribers (active collectors) to this shared flow.

The integer in the resulting StateFlow is not negative and starts with zero for a freshly created shared flow.

This state can be used to react to changes in the number of subscriptions to this shared flow. For example, if you need to call onActive when the first subscriber appears and onInactive when the last one disappears, you can set it up like this:

sharedFlow.subscriptionCount
.map { count -> count 0 } // map count into active/inactive flag
.distinctUntilChanged() // only react to true<->false changes
.onEach { isActive -> // configure an action
if (isActive) onActive() else onInactive()
}
.launchIn(scope) // launch it

Implementation note: the resulting flow does not conflate subscription count.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow/try-emit.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow/try-emit.html index 2d11f17ebc..1ec3e19df3 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow/try-emit.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-shared-flow/try-emit.html @@ -1,72 +1 @@ - - - - - tryEmit - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

tryEmit

-
-
-
-
abstract fun tryEmit(value: T): Boolean

Tries to emit a value to this shared flow without suspending. It returns true if the value was emitted successfully (see below). When this function returns false, it means that a call to a plain emit function would suspend until there is buffer space available.

This call can return false only when the BufferOverflow strategy is SUSPENDand there are subscribers collecting this shared flow.

If there are no subscribers, the buffer is not used. Instead, the most recently emitted value is simply stored into the replay cache if one was configured, displacing the older elements there, or dropped if no replay cache was configured. In any case, tryEmit returns true.

This method is thread-safe and can be safely invoked from concurrent coroutines without external synchronization.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-state-flow.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-state-flow.html index a5484101d1..b97d5eefb2 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-state-flow.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-state-flow.html @@ -1,72 +1 @@ - - - - - MutableStateFlow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

MutableStateFlow

-
-
-
-
fun <T> MutableStateFlow(value: T): MutableStateFlow<T>

Creates a MutableStateFlow with the given initial value.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-state-flow/compare-and-set.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-state-flow/compare-and-set.html index 215cfa6c50..5f2ce72a16 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-state-flow/compare-and-set.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-state-flow/compare-and-set.html @@ -1,72 +1 @@ - - - - - compareAndSet - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

compareAndSet

-
-
-
-
abstract fun compareAndSet(expect: T, update: T): Boolean

Atomically compares the current value with expect and sets it to update if it is equal to expect. The result is true if the value was set to update and false otherwise.

This function use a regular comparison using Any.equals. If both expect and update are equal to the current value, this function returns true, but it does not actually change the reference that is stored in the value.

This method is thread-safe and can be safely invoked from concurrent coroutines without external synchronization.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-state-flow/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-state-flow/index.html index c2485dc45d..b00c741159 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-state-flow/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-state-flow/index.html @@ -1,185 +1 @@ - - - - - MutableStateFlow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

MutableStateFlow

-
-
-
interface MutableStateFlow<T> : StateFlow<T> , MutableSharedFlow<T>

A mutable StateFlow that provides a setter for value. An instance of MutableStateFlow with the given initial value can be created using MutableStateFlow(value) constructor function.

See the StateFlow documentation for details on state flows.

Not stable for inheritance

The MutableStateFlow interface is not stable for inheritance in 3rd party libraries, as new methods might be added to this interface in the future, but is stable for use. Use the MutableStateFlow() constructor function to create an implementation.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun compareAndSet(expect: T, update: T): Boolean

Atomically compares the current value with expect and sets it to update if it is equal to expect. The result is true if the value was set to update and false otherwise.

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract override var value: T

The current value of this state flow.

-
-
-
-
-
-

Extensions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> MutableStateFlow<T>.asStateFlow(): StateFlow<T>

Represents this mutable state flow as a read-only state flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T> MutableStateFlow<T>.getAndUpdate(function: (T) -> T): T

Updates the MutableStateFlow.value atomically using the specified function of its value, and returns its prior value.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T> MutableStateFlow<T>.update(function: (T) -> T)

Updates the MutableStateFlow.value atomically using the specified function of its value.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T> MutableStateFlow<T>.updateAndGet(function: (T) -> T): T

Updates the MutableStateFlow.value atomically using the specified function of its value, and returns the new value.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-state-flow/value.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-state-flow/value.html index 628017bb23..c94adad91f 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-state-flow/value.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-mutable-state-flow/value.html @@ -1,72 +1 @@ - - - - - value - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

value

-
-
-
-
abstract override var value: T

The current value of this state flow.

Setting a value that is equal to the previous one does nothing.

This property is thread-safe and can be safely updated from concurrent coroutines without external synchronization.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-shared-flow/collect.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-shared-flow/collect.html index 794e48d317..c3d0ea1dde 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-shared-flow/collect.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-shared-flow/collect.html @@ -1,72 +1 @@ - - - - - collect - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

collect

-
-
-
-
abstract suspend override fun collect(collector: FlowCollector<T>): Nothing

Accepts the given collector and emits values into it. To emit values from a shared flow into a specific collector, either collector.emitAll(flow) or collect { ... } SAM-conversion can be used.

A shared flow never completes. A call to Flow.collect or any other terminal operator on a shared flow never completes normally.

See also

for implementation and inheritance details.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-shared-flow/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-shared-flow/index.html index a76d222309..40b232027f 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-shared-flow/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-shared-flow/index.html @@ -1,158 +1 @@ - - - - - SharedFlow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

SharedFlow

-
-
-
interface SharedFlow<out T> : Flow<T>

A hotFlow that shares emitted values among all its collectors in a broadcast fashion, so that all collectors get all emitted values. A shared flow is called hot because its active instance exists independently of the presence of collectors. This is opposed to a regular Flow, such as defined by the flow { ... } function, which is cold and is started separately for each collector.

Shared flow never completes. A call to Flow.collect on a shared flow never completes normally, and neither does a coroutine started by the Flow.launchIn function. An active collector of a shared flow is called a subscriber.

A subscriber of a shared flow can be cancelled. This usually happens when the scope in which the coroutine is running is cancelled. A subscriber to a shared flow is always cancellable, and checks for cancellation before each emission. Note that most terminal operators like Flow.toList would also not complete, when applied to a shared flow, but flow-truncating operators like Flow.take and Flow.takeWhile can be used on a shared flow to turn it into a completing one.

A mutable shared flow is created using the MutableSharedFlow(...) constructor function. Its state can be updated by emitting values to it and performing other operations. See the MutableSharedFlow documentation for details.

SharedFlow is useful for broadcasting events that happen inside an application to subscribers that can come and go. For example, the following class encapsulates an event bus that distributes events to all subscribers in a rendezvous manner, suspending until all subscribers receive emitted event:

class EventBus {
private val _events = MutableSharedFlow<Event>() // private mutable shared flow
val events = _events.asSharedFlow() // publicly exposed as read-only shared flow

suspend fun produceEvent(event: Event) {
_events.emit(event) // suspends until all subscribers receive it
}
}

As an alternative to the above usage with the MutableSharedFlow(...) constructor function, any coldFlow can be converted to a shared flow using the shareIn operator.

There is a specialized implementation of shared flow for the case where the most recent state value needs to be shared. See StateFlow for details.

Replay cache and buffer

A shared flow keeps a specific number of the most recent values in its replay cache. Every new subscriber first gets the values from the replay cache and then gets new emitted values. The maximum size of the replay cache is specified when the shared flow is created by the replay parameter. A snapshot of the current replay cache is available via the replayCache property and it can be reset with the MutableSharedFlow.resetReplayCache function.

A replay cache also provides buffer for emissions to the shared flow, allowing slow subscribers to get values from the buffer without suspending emitters. The buffer space determines how much slow subscribers can lag from the fast ones. When creating a shared flow, additional buffer capacity beyond replay can be reserved using the extraBufferCapacity parameter.

A shared flow with a buffer can be configured to avoid suspension of emitters on buffer overflow using the onBufferOverflow parameter, which is equal to one of the entries of the BufferOverflow enum. When a strategy other than SUSPENDED is configured, emissions to the shared flow never suspend.

Buffer overflow condition can happen only when there is at least one subscriber that is not ready to accept the new value. In the absence of subscribers only the most recent replay values are stored and the buffer overflow behavior is never triggered and has no effect. In particular, in the absence of subscribers emitter never suspends despite BufferOverflow.SUSPEND option and BufferOverflow.DROP_LATEST option does not have effect either. Essentially, the behavior in the absence of subscribers is always similar to BufferOverflow.DROP_OLDEST, but the buffer is just of replay size (without any extraBufferCapacity).

Unbuffered shared flow

A default implementation of a shared flow that is created with MutableSharedFlow() constructor function without parameters has no replay cache nor additional buffer. emit call to such a shared flow suspends until all subscribers receive the emitted value and returns immediately if there are no subscribers. Thus, tryEmit call succeeds and returns true only if there are no subscribers (in which case the emitted value is immediately lost).

SharedFlow vs BroadcastChannel

Conceptually shared flow is similar to BroadcastChannel and is designed to completely replace it. It has the following important differences:

  • SharedFlow is simpler, because it does not have to implement all the Channel APIs, which allows for faster and simpler implementation.

  • SharedFlow supports configurable replay and buffer overflow strategy.

  • SharedFlow has a clear separation into a read-only SharedFlow interface and a MutableSharedFlow.

  • SharedFlow cannot be closed like BroadcastChannel and can never represent a failure. All errors and completion signals should be explicitly materialized if needed.

To migrate BroadcastChannel usage to SharedFlow, start by replacing usages of the BroadcastChannel(capacity) constructor with MutableSharedFlow(0, extraBufferCapacity=capacity) (broadcast channel does not replay values to new subscribers). Replace send and trySend calls with emit and tryEmit, and convert subscribers' code to flow operators.

Concurrency

All methods of shared flow are thread-safe and can be safely invoked from concurrent coroutines without external synchronization.

Operator fusion

Application of flowOn, buffer with RENDEZVOUS capacity, or cancellable operators to a shared flow has no effect.

Implementation notes

Shared flow implementation uses a lock to ensure thread-safety, but suspending collector and emitter coroutines are resumed outside of this lock to avoid deadlocks when using unconfined coroutines. Adding new subscribers has O(1) amortized cost, but emitting has O(N) cost, where N is the number of subscribers.

Not stable for inheritance

The SharedFlow interface is not stable for inheritance in 3rd party libraries, as new methods might be added to this interface in the future, but is stable for use. Use the MutableSharedFlow(replay, ...) constructor function to create an implementation.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract suspend override fun collect(collector: FlowCollector<T>): Nothing

Accepts the given collector and emits values into it. To emit values from a shared flow into a specific collector, either collector.emitAll(flow) or collect { ... } SAM-conversion can be used.

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val replayCache: List<T>

A snapshot of the replay cache.

-
-
-
-
-
-

Inheritors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Extensions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> SharedFlow<T>.onSubscription(action: suspend FlowCollector<T>.() -> Unit): SharedFlow<T>

Returns a flow that invokes the given actionafter this shared flow starts to be collected (after the subscription is registered).

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-shared-flow/replay-cache.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-shared-flow/replay-cache.html index ac9aaeb5ea..7794bcdc0c 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-shared-flow/replay-cache.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-shared-flow/replay-cache.html @@ -1,72 +1 @@ - - - - - replayCache - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

replayCache

-
-
-
-
abstract val replayCache: List<T>

A snapshot of the replay cache.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-command/-s-t-a-r-t/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-command/-s-t-a-r-t/index.html index 2c5b556c96..a64336df32 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-command/-s-t-a-r-t/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-command/-s-t-a-r-t/index.html @@ -1,63 +1 @@ - - - - - START - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

START

-
-
-

Starts sharing, launching collection of the upstream flow.

Emitting this command again does not do anything. Emit STOP and then START to restart an upstream flow.

-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-command/-s-t-o-p/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-command/-s-t-o-p/index.html index ac107d0842..25cdd6dbd5 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-command/-s-t-o-p/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-command/-s-t-o-p/index.html @@ -1,63 +1 @@ - - - - - STOP - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

STOP

-
-
-

Stops sharing, cancelling collection of the upstream flow.

-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-command/-s-t-o-p_-a-n-d_-r-e-s-e-t_-r-e-p-l-a-y_-c-a-c-h-e/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-command/-s-t-o-p_-a-n-d_-r-e-s-e-t_-r-e-p-l-a-y_-c-a-c-h-e/index.html index 224b551359..d3778ed6cd 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-command/-s-t-o-p_-a-n-d_-r-e-s-e-t_-r-e-p-l-a-y_-c-a-c-h-e/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-command/-s-t-o-p_-a-n-d_-r-e-s-e-t_-r-e-p-l-a-y_-c-a-c-h-e/index.html @@ -1,63 +1 @@ - - - - - STOP_AND_RESET_REPLAY_CACHE - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

STOP_AND_RESET_REPLAY_CACHE

-
-
-

Stops sharing, cancelling collection of the upstream flow, and resets the SharedFlow.replayCache to its initial state. The shareIn operator calls MutableSharedFlow.resetReplayCache; the stateIn operator resets the value to its original initialValue.

-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-command/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-command/index.html index 3308caa6db..07e839b848 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-command/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-command/index.html @@ -1,130 +1 @@ - - - - - SharingCommand - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

SharingCommand

-
-
-
enum SharingCommand : Enum<SharingCommand>

A command emitted by SharingStarted implementations to control the sharing coroutine in the shareIn and stateIn operators.

-
-
-
-
-

Entries

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Stops sharing, cancelling collection of the upstream flow, and resets the SharedFlow.replayCache to its initial state. The shareIn operator calls MutableSharedFlow.resetReplayCache; the stateIn operator resets the value to its original initialValue.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Stops sharing, cancelling collection of the upstream flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Starts sharing, launching collection of the upstream flow.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-started/-companion/-eagerly.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-started/-companion/-eagerly.html index 561660ab1d..c3e8d224fd 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-started/-companion/-eagerly.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-started/-companion/-eagerly.html @@ -1,72 +1 @@ - - - - - Eagerly - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Eagerly

-
-
-
-
val Eagerly: SharingStarted

Sharing is started immediately and never stops.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-started/-companion/-lazily.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-started/-companion/-lazily.html index c4690f05b7..b11bac88e4 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-started/-companion/-lazily.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-started/-companion/-lazily.html @@ -1,72 +1 @@ - - - - - Lazily - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Lazily

-
-
-
-
val Lazily: SharingStarted

Sharing is started when the first subscriber appears and never stops.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-started/-companion/-while-subscribed.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-started/-companion/-while-subscribed.html index fb63e87627..6299f19de4 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-started/-companion/-while-subscribed.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-started/-companion/-while-subscribed.html @@ -1,72 +1 @@ - - - - - WhileSubscribed - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

WhileSubscribed

-
-
-
-
fun WhileSubscribed(stopTimeoutMillis: Long = 0, replayExpirationMillis: Long = Long.MAX_VALUE): SharingStarted

Sharing is started when the first subscriber appears, immediately stops when the last subscriber disappears (by default), keeping the replay cache forever (by default).

It has the following optional parameters:

  • stopTimeoutMillis — configures a delay (in milliseconds) between the disappearance of the last subscriber and the stopping of the sharing coroutine. It defaults to zero (stop immediately).

  • replayExpirationMillis — configures a delay (in milliseconds) between the stopping of the sharing coroutine and the resetting of the replay cache (which makes the cache empty for the shareIn operator and resets the cached value to the original initialValue for the stateIn operator). It defaults to Long.MAX_VALUE (keep replay cache forever, never reset buffer). Use zero value to expire the cache immediately.

This function throws IllegalArgumentException when either stopTimeoutMillis or replayExpirationMillis are negative.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-started/-companion/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-started/-companion/index.html index ca9746c15c..7379aa37a5 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-started/-companion/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-started/-companion/index.html @@ -1,151 +1 @@ - - - - - Companion - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Companion

-
-
-
object Companion
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun WhileSubscribed(stopTimeoutMillis: Long = 0, replayExpirationMillis: Long = Long.MAX_VALUE): SharingStarted

Sharing is started when the first subscriber appears, immediately stops when the last subscriber disappears (by default), keeping the replay cache forever (by default).

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
val Eagerly: SharingStarted

Sharing is started immediately and never stops.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
val Lazily: SharingStarted

Sharing is started when the first subscriber appears and never stops.

-
-
-
-
-
-

Extensions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun SharingStarted.Companion.WhileSubscribed(stopTimeout: Duration = Duration.ZERO, replayExpiration: Duration = Duration.INFINITE): SharingStarted

Sharing is started when the first subscriber appears, immediately stops when the last subscriber disappears (by default), keeping the replay cache forever (by default).

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-started/command.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-started/command.html index 621978eb50..3c67a0dd98 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-started/command.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-started/command.html @@ -1,72 +1 @@ - - - - - command - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

command

-
-
-
-
abstract fun command(subscriptionCount: StateFlow<Int>): Flow<SharingCommand>

Transforms the subscriptionCount state of the shared flow into the flow of commands that control the sharing coroutine. See the SharingStarted interface documentation for details.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-started/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-started/index.html index 520cd8eb84..c9a49d9ea7 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-started/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-sharing-started/index.html @@ -1,115 +1 @@ - - - - - SharingStarted - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

SharingStarted

-
-
-
fun interface SharingStarted

A strategy for starting and stopping the sharing coroutine in shareIn and stateIn operators.

This functional interface provides a set of built-in strategies: Eagerly, Lazily, WhileSubscribed, and supports custom strategies by implementing this interface's command function.

For example, it is possible to define a custom strategy that starts the upstream only when the number of subscribers exceeds the given threshold and make it an extension on SharingStarted.Companion so that it looks like a built-in strategy on the use-site:

fun SharingStarted.Companion.WhileSubscribedAtLeast(threshold: Int) =
SharingStarted { subscriptionCount: StateFlow<Int> ->
subscriptionCount.map { if (it >= threshold) SharingCommand.START else SharingCommand.STOP }
}

Commands

The SharingStarted strategy works by emitting commands that control upstream flow from its command flow implementation function. Back-to-back emissions of the same command have no effect. Only emission of a different command has effect:

Initially, the upstream flow is stopped and is in the initial state, so the emission of additional STOP and STOP_AND_RESET_REPLAY_CACHE commands will have no effect.

The completion of the command flow normally has no effect (the upstream flow keeps running if it was running). The failure of the command flow cancels the sharing coroutine and the upstream flow.

-
-
-
-
-

Types

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
object Companion
-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun command(subscriptionCount: StateFlow<Int>): Flow<SharingCommand>

Transforms the subscriptionCount state of the shared flow into the flow of commands that control the sharing coroutine. See the SharingStarted interface documentation for details.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-state-flow/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-state-flow/index.html index 94cecfe067..a84cb2b5ee 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-state-flow/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-state-flow/index.html @@ -1,109 +1 @@ - - - - - StateFlow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

StateFlow

-
-
-
interface StateFlow<out T> : SharedFlow<T>

A SharedFlow that represents a read-only state with a single updatable data value that emits updates to the value to its collectors. A state flow is a hot flow because its active instance exists independently of the presence of collectors. Its current value can be retrieved via the value property.

State flow never completes. A call to Flow.collect on a state flow never completes normally, and neither does a coroutine started by the Flow.launchIn function. An active collector of a state flow is called a subscriber.

A mutable state flow is created using MutableStateFlow(value) constructor function with the initial value. The value of mutable state flow can be updated by setting its value property. Updates to the value are always conflated. So a slow collector skips fast updates, but always collects the most recently emitted value.

StateFlow is useful as a data-model class to represent any kind of state. Derived values can be defined using various operators on the flows, with combine operator being especially useful to combine values from multiple state flows using arbitrary functions.

For example, the following class encapsulates an integer state and increments its value on each call to inc:

class CounterModel {
private val _counter = MutableStateFlow(0) // private mutable state flow
val counter = _counter.asStateFlow() // publicly exposed as read-only state flow

fun inc() {
_counter.update { count -> count + 1 } // atomic, safe for concurrent use
}
}

Having two instances of the above CounterModel class one can define the sum of their counters like this:

val aModel = CounterModel()
val bModel = CounterModel()
val sumFlow: Flow<Int> = aModel.counter.combine(bModel.counter) { a, b -> a + b }

As an alternative to the above usage with the MutableStateFlow(...) constructor function, any coldFlow can be converted to a state flow using the stateIn operator.

Strong equality-based conflation

Values in state flow are conflated using Any.equals comparison in a similar way to distinctUntilChanged operator. It is used to conflate incoming updates to value in MutableStateFlow and to suppress emission of the values to collectors when new value is equal to the previously emitted one. State flow behavior with classes that violate the contract for Any.equals is unspecified.

State flow is a shared flow

State flow is a special-purpose, high-performance, and efficient implementation of SharedFlow for the narrow, but widely used case of sharing a state. See the SharedFlow documentation for the basic rules, constraints, and operators that are applicable to all shared flows.

State flow always has an initial value, replays one most recent value to new subscribers, does not buffer any more values, but keeps the last emitted one, and does not support resetReplayCache. A state flow behaves identically to a shared flow when it is created with the following parameters and the distinctUntilChanged operator is applied to it:

// MutableStateFlow(initialValue) is a shared flow with the following parameters:
val shared = MutableSharedFlow(
replay = 1,
onBufferOverflow = BufferOverflow.DROP_OLDEST
)
shared.tryEmit(initialValue) // emit the initial value
val state = shared.distinctUntilChanged() // get StateFlow-like behavior

Use SharedFlow when you need a StateFlow with tweaks in its behavior such as extra buffering, replaying more values, or omitting the initial value.

StateFlow vs ConflatedBroadcastChannel

Conceptually, state flow is similar to ConflatedBroadcastChannel and is designed to completely replace it. It has the following important differences:

  • StateFlow is simpler, because it does not have to implement all the Channel APIs, which allows for faster, garbage-free implementation, unlike ConflatedBroadcastChannel implementation that allocates objects on each emitted value.

  • StateFlow always has a value which can be safely read at any time via value property. Unlike ConflatedBroadcastChannel, there is no way to create a state flow without a value.

  • StateFlow has a clear separation into a read-only StateFlow interface and a MutableStateFlow.

  • StateFlow conflation is based on equality like distinctUntilChanged operator, unlike conflation in ConflatedBroadcastChannel that is based on reference identity.

  • StateFlow cannot be closed like ConflatedBroadcastChannel and can never represent a failure. All errors and completion signals should be explicitly materialized if needed.

StateFlow is designed to better cover typical use-cases of keeping track of state changes in time, taking more pragmatic design choices for the sake of convenience.

To migrate ConflatedBroadcastChannel usage to StateFlow, start by replacing usages of the ConflatedBroadcastChannel() constructor with MutableStateFlow(initialValue), using null as an initial value if you don't have one. Replace send and trySend calls with updates to the state flow's MutableStateFlow.value, and convert subscribers' code to flow operators. You can use the filterNotNull operator to mimic behavior of a ConflatedBroadcastChannel without initial value.

Concurrency

All methods of state flow are thread-safe and can be safely invoked from concurrent coroutines without external synchronization.

Operator fusion

Application of flowOn, conflate, buffer with CONFLATED or RENDEZVOUS capacity, distinctUntilChanged, or cancellable operators to a state flow has no effect.

Implementation notes

State flow implementation is optimized for memory consumption and allocation-freedom. It uses a lock to ensure thread-safety, but suspending collector coroutines are resumed outside of this lock to avoid dead-locks when using unconfined coroutines. Adding new subscribers has O(1) amortized cost, but updating a value has O(N) cost, where N is the number of active subscribers.

Not stable for inheritance

The StateFlow interface is not stable for inheritance in 3rd party libraries, as new methods might be added to this interface in the future, but is stable for use. Use the MutableStateFlow(value) constructor function to create an implementation.

-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val value: T

The current value of this state flow.

-
-
-
-
-
-

Inheritors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-state-flow/value.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-state-flow/value.html index a8a79a5057..6ef8ae1be0 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-state-flow/value.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-state-flow/value.html @@ -1,72 +1 @@ - - - - - value - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

value

-
-
-
-
abstract val value: T

The current value of this state flow.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-while-subscribed.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-while-subscribed.html index 423a25d96c..3eff35f2dd 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/-while-subscribed.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/-while-subscribed.html @@ -1,72 +1 @@ - - - - - WhileSubscribed - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

WhileSubscribed

-
-
-
-
fun SharingStarted.Companion.WhileSubscribed(stopTimeout: Duration = Duration.ZERO, replayExpiration: Duration = Duration.INFINITE): SharingStarted

Sharing is started when the first subscriber appears, immediately stops when the last subscriber disappears (by default), keeping the replay cache forever (by default).

It has the following optional parameters:

  • stopTimeout — configures a delay between the disappearance of the last subscriber and the stopping of the sharing coroutine. It defaults to zero (stop immediately).

  • replayExpiration — configures a delay between the stopping of the sharing coroutine and the resetting of the replay cache (which makes the cache empty for the shareIn operator and resets the cached value to the original initialValue for the stateIn operator). It defaults to Duration.INFINITE (keep replay cache forever, never reset buffer). Use Duration.ZERO value to expire the cache immediately.

This function throws IllegalArgumentException when either stopTimeout or replayExpiration are negative.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/as-flow.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/as-flow.html index 4b1f9ad215..6b2fa3bf27 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/as-flow.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/as-flow.html @@ -1,182 +1 @@ - - - - - asFlow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asFlow

-
-
-
-
fun <T> () -> T.asFlow(): Flow<T>

Creates a cold flow that produces a single value from the given functional type.


fun <T> suspend () -> T.asFlow(): Flow<T>

Creates a cold flow that produces a single value from the given functional type.

Example of usage:

suspend fun remoteCall(): R = ...
fun remoteCallFlow(): Flow<R> = ::remoteCall.asFlow()

fun <T> Iterable<T>.asFlow(): Flow<T>

Creates a cold flow that produces values from the given iterable.


fun <T> Iterator<T>.asFlow(): Flow<T>

Creates a cold flow that produces values from the given iterator.


fun <T> Sequence<T>.asFlow(): Flow<T>

Creates a cold flow that produces values from the given sequence.


fun <T> Array<T>.asFlow(): Flow<T>
fun LongArray.asFlow(): Flow<Long>

Creates a cold flow that produces values from the given array. The flow being cold means that the array components are read every time a terminal operator is applied to the resulting flow.


fun IntArray.asFlow(): Flow<Int>

Creates a cold flow that produces values from the array. The flow being cold means that the array components are read every time a terminal operator is applied to the resulting flow.


fun IntRange.asFlow(): Flow<Int>
fun LongRange.asFlow(): Flow<Long>

Creates a flow that produces values from the range.


fun <T> BroadcastChannel<T>.asFlow(): Flow<T>

Represents the given broadcast channel as a hot flow. Every flow collector will trigger a new broadcast channel subscription.

Cancellation semantics

  1. Flow consumer is cancelled when the original channel is cancelled.

  2. Flow consumer completes normally when the original channel completes (~is closed) normally.

  3. If the flow consumer fails with an exception, subscription is cancelled.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/as-shared-flow.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/as-shared-flow.html index bfdf49d984..663a97b6ec 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/as-shared-flow.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/as-shared-flow.html @@ -1,72 +1 @@ - - - - - asSharedFlow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asSharedFlow

-
-
-
-
fun <T> MutableSharedFlow<T>.asSharedFlow(): SharedFlow<T>

Represents this mutable shared flow as a read-only shared flow.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/as-state-flow.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/as-state-flow.html index dd1b2a8008..a251eb3991 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/as-state-flow.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/as-state-flow.html @@ -1,72 +1 @@ - - - - - asStateFlow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asStateFlow

-
-
-
-
fun <T> MutableStateFlow<T>.asStateFlow(): StateFlow<T>

Represents this mutable state flow as a read-only state flow.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/buffer.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/buffer.html index ddcc1ff3e2..3334c1e3e5 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/buffer.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/buffer.html @@ -1,83 +1 @@ - - - - - buffer - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

buffer

-
-
-
-
fun <T> Flow<T>.buffer(capacity: Int = BUFFERED, onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND): Flow<T>

Buffers flow emissions via channel of a specified capacity and runs collector in a separate coroutine.

Normally, flows are sequential. It means that the code of all operators is executed in the same coroutine. For example, consider the following code using onEach and collect operators:

flowOf("A", "B", "C")
.onEach { println("1$it") }
.collect { println("2$it") }

It is going to be executed in the following order by the coroutine Q that calls this code:

Q : -->-- [1A] -- [2A] -- [1B] -- [2B] -- [1C] -- [2C] -->--

So if the operator's code takes considerable time to execute, then the total execution time is going to be the sum of execution times for all operators.

The buffer operator creates a separate coroutine during execution for the flow it applies to. Consider the following code:

flowOf("A", "B", "C")
.onEach { println("1$it") }
.buffer() // <--------------- buffer between onEach and collect
.collect { println("2$it") }

It will use two coroutines for execution of the code. A coroutine Q that calls this code is going to execute collect, and the code before buffer will be executed in a separate new coroutine P concurrently with Q:

P : -->-- [1A] -- [1B] -- [1C] ---------->--  // flowOf(...).onEach { ... }

|
| channel // buffer()
V

Q : -->---------- [2A] -- [2B] -- [2C] -->-- // collect

When the operator's code takes some time to execute, this decreases the total execution time of the flow. A channel is used between the coroutines to send elements emitted by the coroutine P to the coroutine Q. If the code before buffer operator (in the coroutine P) is faster than the code after buffer operator (in the coroutine Q), then this channel will become full at some point and will suspend the producer coroutine P until the consumer coroutine Q catches up. The capacity parameter defines the size of this buffer.

Buffer overflow

By default, the emitter is suspended when the buffer overflows, to let collector catch up. This strategy can be overridden with an optional onBufferOverflow parameter so that the emitter is never suspended. In this case, on buffer overflow either the oldest value in the buffer is dropped with the DROP_OLDEST strategy and the latest emitted value is added to the buffer, or the latest value that is being emitted is dropped with the DROP_LATEST strategy, keeping the buffer intact. To implement either of the custom strategies, a buffer of at least one element is used.

Operator fusion

Adjacent applications of channelFlow, flowOn, buffer, and produceIn are always fused so that only one properly configured channel is used for execution.

Explicitly specified buffer capacity takes precedence over buffer() or buffer(Channel.BUFFERED) calls, which effectively requests a buffer of any size. Multiple requests with a specified buffer size produce a buffer with the sum of the requested buffer sizes.

A buffer call with a non-default value of the onBufferOverflow parameter overrides all immediately preceding buffering operators, because it never suspends its upstream, and thus no upstream buffer would ever be used.

Conceptual implementation

The actual implementation of buffer is not trivial due to the fusing, but conceptually its basic implementation is equivalent to the following code that can be written using produce coroutine builder to produce a channel and consumeEach extension to consume it:

fun <T> Flow<T>.buffer(capacity: Int = DEFAULT): Flow<T> = flow {
coroutineScope { // limit the scope of concurrent producer coroutine
val channel = produce(capacity = capacity) {
collect { send(it) } // send all to channel
}
// emit all received values
channel.consumeEach { emit(it) }
}
}

Conflation

Usage of this function with capacity of Channel.CONFLATED is a shortcut to buffer(onBufferOverflow = BufferOverflow.DROP_OLDEST), and is available via a separate conflate operator. See its documentation for details.

Parameters

capacity

type/capacity of the buffer between coroutines. Allowed values are the same as in Channel(...) factory function: BUFFERED (by default), CONFLATED, RENDEZVOUS, UNLIMITED or a non-negative value indicating an explicitly requested size.

onBufferOverflow

configures an action on buffer overflow (optional, defaults to SUSPEND, supported only when capacity >= 0 or capacity == Channel.BUFFERED, implicitly creates a channel with at least one buffered element).


fun <T> Flow<T>.buffer(capacity: Int = BUFFERED): Flow<T>
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/callback-flow.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/callback-flow.html index 29e852c696..c1c9df67d7 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/callback-flow.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/callback-flow.html @@ -1,72 +1 @@ - - - - - callbackFlow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

callbackFlow

-
-
-
-
fun <T> callbackFlow(block: suspend ProducerScope<T>.() -> Unit): Flow<T>

Creates an instance of a coldFlow with elements that are sent to a SendChannel provided to the builder's block of code via ProducerScope. It allows elements to be produced by code that is running in a different context or concurrently.

The resulting flow is cold, which means that block is called every time a terminal operator is applied to the resulting flow.

This builder ensures thread-safety and context preservation, thus the provided ProducerScope can be used from any context, e.g. from a callback-based API. The resulting flow completes as soon as the code in the block completes. awaitClose should be used to keep the flow running, otherwise the channel will be closed immediately when block completes. awaitClose argument is called either when a flow consumer cancels the flow collection or when a callback-based API invokes SendChannel.close manually and is typically used to cleanup the resources after the completion, e.g. unregister a callback. Using awaitClose is mandatory in order to prevent memory leaks when the flow collection is cancelled, otherwise the callback may keep running even when the flow collector is already completed. To avoid such leaks, this method throws IllegalStateException if block returns, but the channel is not closed yet.

A channel with the default buffer size is used. Use the buffer operator on the resulting flow to specify a user-defined value and to control what happens when data is produced faster than consumed, i.e. to control the back-pressure behavior.

Adjacent applications of callbackFlow, flowOn, buffer, and produceIn are always fused so that only one properly configured channel is used for execution.

Example of usage that converts a multi-shot callback API to a flow. For single-shot callbacks use suspendCancellableCoroutine.

fun flowFrom(api: CallbackBasedApi): Flow<T> = callbackFlow {
val callback = object : Callback { // Implementation of some callback interface
override fun onNextValue(value: T) {
// To avoid blocking you can configure channel capacity using
// either buffer(Channel.CONFLATED) or buffer(Channel.UNLIMITED) to avoid overfill
trySendBlocking(value)
.onFailure { throwable ->
// Downstream has been cancelled or failed, can log here
}
}
override fun onApiError(cause: Throwable) {
cancel(CancellationException("API Error", cause))
}
override fun onCompleted() = channel.close()
}
api.register(callback)
/*
* Suspends until either 'onCompleted'/'onApiError' from the callback is invoked
* or flow collector is cancelled (e.g. by 'take(1)' or because a collector's coroutine was cancelled).
* In both cases, callback will be properly unregistered.
*/
awaitClose { api.unregister(callback) }
}

The callback register/unregister methods provided by an external API must be thread-safe, because awaitClose block can be called at any time due to asynchronous nature of cancellation, even concurrently with the call of the callback.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/cancellable.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/cancellable.html index ec2c03f929..9a3eedf86b 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/cancellable.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/cancellable.html @@ -1,72 +1 @@ - - - - - cancellable - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

cancellable

-
-
-
-
fun <T> Flow<T>.cancellable(): Flow<T>

Returns a flow which checks cancellation status on each emission and throws the corresponding cancellation cause if flow collector was cancelled. Note that flow builder and all implementations of SharedFlow are cancellable by default.

This operator provides a shortcut for .onEach { currentCoroutineContext().ensureActive() }. See ensureActive for details.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/catch.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/catch.html index 90db91c540..ffe1ed94ed 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/catch.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/catch.html @@ -1,72 +1 @@ - - - - - catch - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

catch

-
-
-
-
fun <T> Flow<T>.catch(action: suspend FlowCollector<T>.(cause: Throwable) -> Unit): Flow<T>

Catches exceptions in the flow completion and calls a specified action with the caught exception. This operator is transparent to exceptions that occur in downstream flow and does not catch exceptions that are thrown to cancel the flow.

For example:

flow { emitData() }
.map { computeOne(it) }
.catch { ... } // catches exceptions in emitData and computeOne
.map { computeTwo(it) }
.collect { process(it) } // throws exceptions from process and computeTwo

Conceptually, the action of catch operator is similar to wrapping the code of upstream flows with try { ... } catch (e: Throwable) { action(e) }.

Any exception in the action code itself proceeds downstream where it can be caught by further catch operators if needed. If a particular exception does not need to be caught it can be rethrown from the action of catch operator. For example:

flow.catch { e ->
if (e !is IOException) throw e // rethrow all but IOException
// e is IOException here
...
}

The action code has FlowCollector as a receiver and can emit values downstream. For example, caught exception can be replaced with some wrapper value for errors:

flow.catch { e -> emit(ErrorWrapperValue(e)) }

The action can also use emitAll to fallback on some other flow in case of an error. However, to retry an original flow use retryWhen operator that can retry the flow multiple times without introducing ever-growing stack of suspending calls.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/channel-flow.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/channel-flow.html index dfd05a1787..bca469a0b9 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/channel-flow.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/channel-flow.html @@ -1,72 +1 @@ - - - - - channelFlow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

channelFlow

-
-
-
-
fun <T> channelFlow(block: suspend ProducerScope<T>.() -> Unit): Flow<T>

Creates an instance of a coldFlow with elements that are sent to a SendChannel provided to the builder's block of code via ProducerScope. It allows elements to be produced by code that is running in a different context or concurrently. The resulting flow is cold, which means that block is called every time a terminal operator is applied to the resulting flow.

This builder ensures thread-safety and context preservation, thus the provided ProducerScope can be used concurrently from different contexts. The resulting flow completes as soon as the code in the block and all its children completes. Use awaitClose as the last statement to keep it running. A more detailed example is provided in the documentation of callbackFlow.

A channel with the default buffer size is used. Use the buffer operator on the resulting flow to specify a user-defined value and to control what happens when data is produced faster than consumed, i.e. to control the back-pressure behavior.

Adjacent applications of channelFlow, flowOn, buffer, and produceIn are always fused so that only one properly configured channel is used for execution.

Examples of usage:

fun <T> Flow<T>.merge(other: Flow<T>): Flow<T> = channelFlow {
// collect from one coroutine and send it
launch {
collect { send(it) }
}
// collect and send from this coroutine, too, concurrently
other.collect { send(it) }
}

fun <T> contextualFlow(): Flow<T> = channelFlow {
// send from one coroutine
launch(Dispatchers.IO) {
send(computeIoValue())
}
// send from another coroutine, concurrently
launch(Dispatchers.Default) {
send(computeCpuValue())
}
}
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/collect-indexed.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/collect-indexed.html index a5f279b060..2a4f7eae17 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/collect-indexed.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/collect-indexed.html @@ -1,72 +1 @@ - - - - - collectIndexed - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

collectIndexed

-
-
-
-
inline suspend fun <T> Flow<T>.collectIndexed(crossinline action: suspend (index: Int, T) -> Unit)

Terminal flow operator that collects the given flow with a provided action that takes the index of an element (zero-based) and the element. If any exception occurs during collect or in the provided flow, this exception is rethrown from this method.

See also collect and withIndex.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/collect-latest.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/collect-latest.html index 9c3a31c807..afdb1bdbdb 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/collect-latest.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/collect-latest.html @@ -1,72 +1 @@ - - - - - collectLatest - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

collectLatest

-
-
-
-
suspend fun <T> Flow<T>.collectLatest(action: suspend (T) -> Unit)

Terminal flow operator that collects the given flow with a provided action. The crucial difference from collect is that when the original flow emits a new value then the action block for the previous value is cancelled.

It can be demonstrated by the following example:

flow {
emit(1)
delay(50)
emit(2)
}.collectLatest { value ->
println("Collecting $value")
delay(100) // Emulate work
println("$value collected")
}

prints "Collecting 1, Collecting 2, 2 collected"

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/collect.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/collect.html index 242d1165dd..3069fa77d2 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/collect.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/collect.html @@ -1,72 +1 @@ - - - - - collect - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

collect

-
-
-
-
suspend fun Flow<*>.collect()

Terminal flow operator that collects the given flow but ignores all emitted values. If any exception occurs during collect or in the provided flow, this exception is rethrown from this method.

It is a shorthand for collect {}.

This operator is usually used with onEach, onCompletion and catch operators to process all emitted values and handle an exception that might occur in the upstream flow or during processing, for example:

flow
.onEach { value -> process(value) }
.catch { e -> handleException(e) }
.collect() // trigger collection of the flow
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/combine-transform.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/combine-transform.html index dab3573e1d..eaa05cb995 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/combine-transform.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/combine-transform.html @@ -1,138 +1 @@ - - - - - combineTransform - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

combineTransform

-
-
-
-
@JvmName(name = "flowCombineTransform")
fun <T1, T2, R> Flow<T1>.combineTransform(flow: Flow<T2>, transform: suspend FlowCollector<R>.(T1, T2) -> Unit): Flow<R>

Returns a Flow whose values are generated by transform function that process the most recently emitted values by each flow.

The receiver of the transform is FlowCollector and thus transform is a generic function that may transform emitted element, skip it or emit it multiple times.

Its usage can be demonstrated with the following example:

val flow = requestFlow()
val flow2 = searchEngineFlow()
flow.combineTransform(flow2) { request, searchEngine ->
emit("Downloading in progress")
val result = download(request, searchEngine)
emit(result)
}

fun <T1, T2, R> combineTransform(    flow: Flow<T1>,     flow2: Flow<T2>,     transform: suspend FlowCollector<R>.(T1, T2) -> Unit): Flow<R>

Returns a Flow whose values are generated by transform function that process the most recently emitted values by each flow.

The receiver of the transform is FlowCollector and thus transform is a generic function that may transform emitted element, skip it or emit it multiple times.

Its usage can be demonstrated with the following example:

val flow = requestFlow()
val flow2 = searchEngineFlow()
combineTransform(flow, flow2) { request, searchEngine ->
emit("Downloading in progress")
val result = download(request, searchEngine)
emit(result)
}

fun <T1, T2, T3, R> combineTransform(    flow: Flow<T1>,     flow2: Flow<T2>,     flow3: Flow<T3>,     transform: suspend FlowCollector<R>.(T1, T2, T3) -> Unit): Flow<R>
fun <T1, T2, T3, T4, R> combineTransform(    flow: Flow<T1>,     flow2: Flow<T2>,     flow3: Flow<T3>,     flow4: Flow<T4>,     transform: suspend FlowCollector<R>.(T1, T2, T3, T4) -> Unit): Flow<R>
fun <T1, T2, T3, T4, T5, R> combineTransform(    flow: Flow<T1>,     flow2: Flow<T2>,     flow3: Flow<T3>,     flow4: Flow<T4>,     flow5: Flow<T5>,     transform: suspend FlowCollector<R>.(T1, T2, T3, T4, T5) -> Unit): Flow<R>
inline fun <T, R> combineTransform(vararg flows: Flow<T>, crossinline transform: suspend FlowCollector<R>.(Array<T>) -> Unit): Flow<R>
inline fun <T, R> combineTransform(flows: Iterable<Flow<T>>, crossinline transform: suspend FlowCollector<R>.(Array<T>) -> Unit): Flow<R>

Returns a Flow whose values are generated by transform function that process the most recently emitted values by each flow.

The receiver of the transform is FlowCollector and thus transform is a generic function that may transform emitted element, skip it or emit it multiple times.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/combine.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/combine.html index 554382c1d8..2c53afdda2 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/combine.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/combine.html @@ -1,138 +1 @@ - - - - - combine - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

combine

-
-
-
-
@JvmName(name = "flowCombine")
fun <T1, T2, R> Flow<T1>.combine(flow: Flow<T2>, transform: suspend (T1, T2) -> R): Flow<R>

Returns a Flow whose values are generated with transform function by combining the most recently emitted values by each flow.

It can be demonstrated with the following example:

val flow = flowOf(1, 2).onEach { delay(10) }
val flow2 = flowOf("a", "b", "c").onEach { delay(15) }
flow.combine(flow2) { i, s -> i.toString() + s }.collect {
println(it) // Will print "1a 2a 2b 2c"
}

This function is a shorthand for `flow.combineTransform(flow2) { a, b -> emit(transform(a, b)) }


fun <T1, T2, R> combine(    flow: Flow<T1>,     flow2: Flow<T2>,     transform: suspend (T1, T2) -> R): Flow<R>

Returns a Flow whose values are generated with transform function by combining the most recently emitted values by each flow.

It can be demonstrated with the following example:

val flow = flowOf(1, 2).onEach { delay(10) }
val flow2 = flowOf("a", "b", "c").onEach { delay(15) }
combine(flow, flow2) { i, s -> i.toString() + s }.collect {
println(it) // Will print "1a 2a 2b 2c"
}

This function is a shorthand for `combineTransform(flow, flow2) { a, b -> emit(transform(a, b)) }


fun <T1, T2, T3, R> combine(    flow: Flow<T1>,     flow2: Flow<T2>,     flow3: Flow<T3>,     transform: suspend (T1, T2, T3) -> R): Flow<R>
fun <T1, T2, T3, T4, R> combine(    flow: Flow<T1>,     flow2: Flow<T2>,     flow3: Flow<T3>,     flow4: Flow<T4>,     transform: suspend (T1, T2, T3, T4) -> R): Flow<R>
fun <T1, T2, T3, T4, T5, R> combine(    flow: Flow<T1>,     flow2: Flow<T2>,     flow3: Flow<T3>,     flow4: Flow<T4>,     flow5: Flow<T5>,     transform: suspend (T1, T2, T3, T4, T5) -> R): Flow<R>
inline fun <T, R> combine(vararg flows: Flow<T>, crossinline transform: suspend (Array<T>) -> R): Flow<R>
inline fun <T, R> combine(flows: Iterable<Flow<T>>, crossinline transform: suspend (Array<T>) -> R): Flow<R>

Returns a Flow whose values are generated with transform function by combining the most recently emitted values by each flow.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/conflate.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/conflate.html index d29a539adc..e9117e6a0f 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/conflate.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/conflate.html @@ -1,72 +1 @@ - - - - - conflate - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

conflate

-
-
-
-
fun <T> Flow<T>.conflate(): Flow<T>

Conflates flow emissions via conflated channel and runs collector in a separate coroutine. The effect of this is that emitter is never suspended due to a slow collector, but collector always gets the most recent value emitted.

For example, consider the flow that emits integers from 1 to 30 with 100 ms delay between them:

val flow = flow {
for (i in 1..30) {
delay(100)
emit(i)
}
}

Applying conflate() operator to it allows a collector that delays 1 second on each element to get integers 1, 10, 20, 30:

val result = flow.conflate().onEach { delay(1000) }.toList()
assertEquals(listOf(1, 10, 20, 30), result)

Note that conflate operator is a shortcut for buffer with capacity of Channel.CONFLATED, which is, in turn, a shortcut to a buffer that only keeps the latest element as created by buffer(onBufferOverflow = BufferOverflow.DROP_OLDEST).

Operator fusion

Adjacent applications of conflate/buffer, channelFlow, flowOn and produceIn are always fused so that only one properly configured channel is used for execution. Conflation takes precedence over buffer() calls with any other capacity.

Note that any instance of StateFlow already behaves as if conflate operator is applied to it, so applying conflate to a StateFlow has no effect. See StateFlow documentation on Operator Fusion.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/consume-as-flow.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/consume-as-flow.html index ca216cffde..22da4933e0 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/consume-as-flow.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/consume-as-flow.html @@ -1,72 +1 @@ - - - - - consumeAsFlow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

consumeAsFlow

-
-
-
-
fun <T> ReceiveChannel<T>.consumeAsFlow(): Flow<T>

Represents the given receive channel as a hot flow and consumes the channel on the first collection from this flow. The resulting flow can be collected just once and throws IllegalStateException when trying to collect it more than once.

See also receiveAsFlow which supports multiple collectors of the resulting flow.

Cancellation semantics

  • Flow collector is cancelled when the original channel is closed with an exception.

  • Flow collector completes normally when the original channel is closed normally.

  • If the flow collector fails with an exception, the source channel is cancelled.

Operator fusion

Adjacent applications of flowOn, buffer, conflate, and produceIn to the result of consumeAsFlow are fused. In particular, produceIn returns the original channel (but throws IllegalStateException on repeated calls). Calls to flowOn have generally no effect, unless buffer is used to explicitly request buffering.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/count.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/count.html index 383f0662e3..90553b5563 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/count.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/count.html @@ -1,83 +1 @@ - - - - - count - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

count

-
-
-
-
suspend fun <T> Flow<T>.count(): Int

Returns the number of elements in this flow.


suspend fun <T> Flow<T>.count(predicate: suspend (T) -> Boolean): Int

Returns the number of elements matching the given predicate.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/debounce.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/debounce.html index 7a80f4b962..a846028170 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/debounce.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/debounce.html @@ -1,105 +1 @@ - - - - - debounce - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

debounce

-
-
-
-
fun <T> Flow<T>.debounce(timeoutMillis: Long): Flow<T>

Returns a flow that mirrors the original flow, but filters out values that are followed by the newer values within the given timeout. The latest value is always emitted.

Example:

flow {
emit(1)
delay(90)
emit(2)
delay(90)
emit(3)
delay(1010)
emit(4)
delay(1010)
emit(5)
}.debounce(1000)

produces the following emissions

3, 4, 5

Note that the resulting flow does not emit anything as long as the original flow emits items faster than every timeoutMillis milliseconds.


fun <T> Flow<T>.debounce(timeoutMillis: (T) -> Long): Flow<T>

Returns a flow that mirrors the original flow, but filters out values that are followed by the newer values within the given timeout. The latest value is always emitted.

A variation of debounce that allows specifying the timeout value dynamically.

Example:

flow {
emit(1)
delay(90)
emit(2)
delay(90)
emit(3)
delay(1010)
emit(4)
delay(1010)
emit(5)
}.debounce {
if (it == 1) {
0L
} else {
1000L
}
}

produces the following emissions

1, 3, 4, 5

Note that the resulting flow does not emit anything as long as the original flow emits items faster than every timeoutMillis milliseconds.

Parameters

timeoutMillis

T is the emitted value and the return value is timeout in milliseconds.


fun <T> Flow<T>.debounce(timeout: Duration): Flow<T>

Returns a flow that mirrors the original flow, but filters out values that are followed by the newer values within the given timeout. The latest value is always emitted.

Example:

flow {
emit(1)
delay(90.milliseconds)
emit(2)
delay(90.milliseconds)
emit(3)
delay(1010.milliseconds)
emit(4)
delay(1010.milliseconds)
emit(5)
}.debounce(1000.milliseconds)

produces the following emissions

3, 4, 5

Note that the resulting flow does not emit anything as long as the original flow emits items faster than every timeout milliseconds.


@JvmName(name = "debounceDuration")
fun <T> Flow<T>.debounce(timeout: (T) -> Duration): Flow<T>

Returns a flow that mirrors the original flow, but filters out values that are followed by the newer values within the given timeout. The latest value is always emitted.

A variation of debounce that allows specifying the timeout value dynamically.

Example:

flow {
emit(1)
delay(90.milliseconds)
emit(2)
delay(90.milliseconds)
emit(3)
delay(1010.milliseconds)
emit(4)
delay(1010.milliseconds)
emit(5)
}.debounce {
if (it == 1) {
0.milliseconds
} else {
1000.milliseconds
}
}

produces the following emissions

1, 3, 4, 5

Note that the resulting flow does not emit anything as long as the original flow emits items faster than every timeout unit.

Parameters

timeout

T is the emitted value and the return value is timeout in Duration.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/distinct-until-changed-by.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/distinct-until-changed-by.html index 2d0003eca0..524d27ec11 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/distinct-until-changed-by.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/distinct-until-changed-by.html @@ -1,72 +1 @@ - - - - - distinctUntilChangedBy - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

distinctUntilChangedBy

-
-
-
-
fun <T, K> Flow<T>.distinctUntilChangedBy(keySelector: (T) -> K): Flow<T>

Returns flow where all subsequent repetitions of the same key are filtered out, where key is extracted with keySelector function.

Note that repeated application of distinctUntilChanged operator with the same parameter has no effect.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/distinct-until-changed.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/distinct-until-changed.html index 1105aab657..d6312783ef 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/distinct-until-changed.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/distinct-until-changed.html @@ -1,83 +1 @@ - - - - - distinctUntilChanged - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

distinctUntilChanged

-
-
-
-
fun <T> Flow<T>.distinctUntilChanged(): Flow<T>

Returns flow where all subsequent repetitions of the same value are filtered out.

Note that any instance of StateFlow already behaves as if distinctUntilChanged operator is applied to it, so applying distinctUntilChanged to a StateFlow has no effect. See StateFlow documentation on Operator Fusion. Also, repeated application of distinctUntilChanged operator on any flow has no effect.


fun <T> Flow<T>.distinctUntilChanged(areEquivalent: (T, T) -> Boolean): Flow<T>

Returns flow where all subsequent repetitions of the same value are filtered out, when compared with each other via the provided areEquivalent function.

Note that repeated application of distinctUntilChanged operator with the same parameter has no effect.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/drop-while.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/drop-while.html index 00f1ad7683..e5a101c671 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/drop-while.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/drop-while.html @@ -1,72 +1 @@ - - - - - dropWhile - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

dropWhile

-
-
-
-
fun <T> Flow<T>.dropWhile(predicate: suspend (T) -> Boolean): Flow<T>

Returns a flow containing all elements except first elements that satisfy the given predicate.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/drop.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/drop.html index 3eba5218f6..58be5233e4 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/drop.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/drop.html @@ -1,72 +1 @@ - - - - - drop - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

drop

-
-
-
-
fun <T> Flow<T>.drop(count: Int): Flow<T>

Returns a flow that ignores first count elements. Throws IllegalArgumentException if count is negative.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/emit-all.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/emit-all.html index 2f7e6dadc6..970f3a7a1b 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/emit-all.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/emit-all.html @@ -1,83 +1 @@ - - - - - emitAll - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

emitAll

-
-
-
-
suspend fun <T> FlowCollector<T>.emitAll(channel: ReceiveChannel<T>)

Emits all elements from the given channel to this flow collector and cancels (consumes) the channel afterwards. If you need to iterate over the channel without consuming it, a regular for loop should be used instead.

Note, that emitting values from a channel into a flow is not atomic. A value that was received from the channel many not reach the flow collector if it was cancelled and will be lost.

This function provides a more efficient shorthand for channel.consumeEach { value -> emit(value) }. See consumeEach.


suspend fun <T> FlowCollector<T>.emitAll(flow: Flow<T>)

Collects all the values from the given flow and emits them to the collector. It is a shorthand for flow.collect { value -> emit(value) }.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/empty-flow.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/empty-flow.html index 3d9d25697f..b145cfaf1f 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/empty-flow.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/empty-flow.html @@ -1,72 +1 @@ - - - - - emptyFlow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

emptyFlow

-
-
-
-
fun <T> emptyFlow(): Flow<T>

Returns an empty flow.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/filter-is-instance.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/filter-is-instance.html index 4cf2ec56bd..54ed4c82dc 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/filter-is-instance.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/filter-is-instance.html @@ -1,72 +1 @@ - - - - - filterIsInstance - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

filterIsInstance

-
-
-
-
inline fun <R> Flow<*>.filterIsInstance(): Flow<R>

Returns a flow containing only values that are instances of specified type R.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/filter-not-null.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/filter-not-null.html index 8af0650f64..0ff660fa78 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/filter-not-null.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/filter-not-null.html @@ -1,72 +1 @@ - - - - - filterNotNull - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

filterNotNull

-
-
-
-
fun <T : Any> Flow<T?>.filterNotNull(): Flow<T>

Returns a flow containing only values of the original flow that are not null.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/filter-not.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/filter-not.html index d237f4a19a..9a81af972f 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/filter-not.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/filter-not.html @@ -1,72 +1 @@ - - - - - filterNot - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

filterNot

-
-
-
-
inline fun <T> Flow<T>.filterNot(crossinline predicate: suspend (T) -> Boolean): Flow<T>

Returns a flow containing only values of the original flow that do not match the given predicate.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/filter.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/filter.html index ce949135e6..2719b3756a 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/filter.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/filter.html @@ -1,72 +1 @@ - - - - - filter - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

filter

-
-
-
-
inline fun <T> Flow<T>.filter(crossinline predicate: suspend (T) -> Boolean): Flow<T>

Returns a flow containing only values of the original flow that match the given predicate.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/first-or-null.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/first-or-null.html index 4e370f00b7..df7a0c1511 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/first-or-null.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/first-or-null.html @@ -1,83 +1 @@ - - - - - firstOrNull - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

firstOrNull

-
-
-
-
suspend fun <T> Flow<T>.firstOrNull(): T?

The terminal operator that returns the first element emitted by the flow and then cancels flow's collection. Returns null if the flow was empty.


suspend fun <T> Flow<T>.firstOrNull(predicate: suspend (T) -> Boolean): T?

The terminal operator that returns the first element emitted by the flow matching the given predicate and then cancels flow's collection. Returns null if the flow did not contain an element matching the predicate.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/first.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/first.html index 68958b39a2..76289e9971 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/first.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/first.html @@ -1,83 +1 @@ - - - - - first - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

first

-
-
-
-
suspend fun <T> Flow<T>.first(): T

The terminal operator that returns the first element emitted by the flow and then cancels flow's collection. Throws NoSuchElementException if the flow was empty.


suspend fun <T> Flow<T>.first(predicate: suspend (T) -> Boolean): T

The terminal operator that returns the first element emitted by the flow matching the given predicate and then cancels flow's collection. Throws NoSuchElementException if the flow has not contained elements matching the predicate.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/flat-map-concat.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/flat-map-concat.html index e6d79d9dd4..e40b540eb9 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/flat-map-concat.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/flat-map-concat.html @@ -1,72 +1 @@ - - - - - flatMapConcat - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

flatMapConcat

-
-
-
-
fun <T, R> Flow<T>.flatMapConcat(transform: suspend (T) -> Flow<R>): Flow<R>

Transforms elements emitted by the original flow by applying transform, that returns another flow, and then concatenating and flattening these flows.

This method is a shortcut for map(transform).flattenConcat(). See flattenConcat.

Note that even though this operator looks very familiar, we discourage its usage in a regular application-specific flows. Most likely, suspending operation in map operator will be sufficient and linear transformations are much easier to reason about.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/flat-map-latest.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/flat-map-latest.html index a894696d35..0c594c1abd 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/flat-map-latest.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/flat-map-latest.html @@ -1,72 +1 @@ - - - - - flatMapLatest - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

flatMapLatest

-
-
-
-
inline fun <T, R> Flow<T>.flatMapLatest(crossinline transform: suspend (T) -> Flow<R>): Flow<R>

Returns a flow that switches to a new flow produced by transform function every time the original flow emits a value. When the original flow emits a new value, the previous flow produced by transform block is cancelled.

For example, the following flow:

flow {
emit("a")
delay(100)
emit("b")
}.flatMapLatest { value ->
flow {
emit(value)
delay(200)
emit(value + "_last")
}
}

produces a b b_last

This operator is buffered by default and size of its output buffer can be changed by applying subsequent buffer operator.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/flat-map-merge.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/flat-map-merge.html index d1aadc59c2..437a3017fc 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/flat-map-merge.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/flat-map-merge.html @@ -1,72 +1 @@ - - - - - flatMapMerge - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

flatMapMerge

-
-
-
-
fun <T, R> Flow<T>.flatMapMerge(concurrency: Int = DEFAULT_CONCURRENCY, transform: suspend (T) -> Flow<R>): Flow<R>

Transforms elements emitted by the original flow by applying transform, that returns another flow, and then merging and flattening these flows.

This operator calls transformsequentially and then merges the resulting flows with a concurrency limit on the number of concurrently collected flows. It is a shortcut for map(transform).flattenMerge(concurrency). See flattenMerge for details.

Note that even though this operator looks very familiar, we discourage its usage in a regular application-specific flows. Most likely, suspending operation in map operator will be sufficient and linear transformations are much easier to reason about.

Operator fusion

Applications of flowOn, buffer, and produceInafter this operator are fused with its concurrent merging so that only one properly configured channel is used for execution of merging logic.

Parameters

concurrency

controls the number of in-flight flows, at most concurrency flows are collected at the same time. By default, it is equal to DEFAULT_CONCURRENCY.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/flatten-concat.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/flatten-concat.html index 353ed9e973..2bbdabc46d 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/flatten-concat.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/flatten-concat.html @@ -1,72 +1 @@ - - - - - flattenConcat - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

flattenConcat

-
-
-
-
fun <T> Flow<Flow<T>>.flattenConcat(): Flow<T>

Flattens the given flow of flows into a single flow in a sequential manner, without interleaving nested flows.

Inner flows are collected by this operator sequentially.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/flatten-merge.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/flatten-merge.html index 5727e04969..d7cf9209cf 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/flatten-merge.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/flatten-merge.html @@ -1,72 +1 @@ - - - - - flattenMerge - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

flattenMerge

-
-
-
-
fun <T> Flow<Flow<T>>.flattenMerge(concurrency: Int = DEFAULT_CONCURRENCY): Flow<T>

Flattens the given flow of flows into a single flow with a concurrency limit on the number of concurrently collected flows.

If concurrency is more than 1, then inner flows are collected by this operator concurrently. With concurrency == 1 this operator is identical to flattenConcat.

Operator fusion

Applications of flowOn, buffer, and produceInafter this operator are fused with its concurrent merging so that only one properly configured channel is used for execution of merging logic.

When concurrency is greater than 1, this operator is buffered by default and size of its output buffer can be changed by applying subsequent buffer operator.

Parameters

concurrency

controls the number of in-flight flows, at most concurrency flows are collected at the same time. By default, it is equal to DEFAULT_CONCURRENCY.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/flow-of.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/flow-of.html index 85c7d00d74..5fe7b4ab26 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/flow-of.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/flow-of.html @@ -1,83 +1 @@ - - - - - flowOf - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

flowOf

-
-
-
-
fun <T> flowOf(vararg elements: T): Flow<T>

Creates a flow that produces values from the specified vararg-arguments.

Example of usage:

flowOf(1, 2, 3)

fun <T> flowOf(value: T): Flow<T>

Creates a flow that produces the given value.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/flow-on.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/flow-on.html index b562b2ace0..b9f327c423 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/flow-on.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/flow-on.html @@ -1,72 +1 @@ - - - - - flowOn - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

flowOn

-
-
-
-
fun <T> Flow<T>.flowOn(context: CoroutineContext): Flow<T>

Changes the context where this flow is executed to the given context. This operator is composable and affects only preceding operators that do not have its own context. This operator is context preserving: contextdoes not leak into the downstream flow.

For example:

withContext(Dispatchers.Main) {
val singleValue = intFlow // will be executed on IO if context wasn't specified before
.map { ... } // Will be executed in IO
.flowOn(Dispatchers.IO)
.filter { ... } // Will be executed in Default
.flowOn(Dispatchers.Default)
.single() // Will be executed in the Main
}

For more explanation of context preservation please refer to Flow documentation.

This operator retains a sequential nature of flow if changing the context does not call for changing the dispatcher. Otherwise, if changing dispatcher is required, it collects flow emissions in one coroutine that is run using a specified context and emits them from another coroutines with the original collector's context using a channel with a default buffer size between two coroutines similarly to buffer operator, unless buffer operator is explicitly called before or after flowOn, which requests buffering behavior and specifies channel size.

Note, that flows operating across different dispatchers might lose some in-flight elements when cancelled. In particular, this operator ensures that downstream flow does not resume on cancellation even if the element was already emitted by the upstream flow.

Operator fusion

Adjacent applications of channelFlow, flowOn, buffer, and produceIn are always fused so that only one properly configured channel is used for execution.

Multiple flowOn operators fuse to a single flowOn with a combined context. The elements of the context of the first flowOn operator naturally take precedence over the elements of the second flowOn operator when they have the same context keys, for example:

flow.map { ... } // Will be executed in IO
.flowOn(Dispatchers.IO) // This one takes precedence
.flowOn(Dispatchers.Default)

Note that an instance of SharedFlow does not have an execution context by itself, so applying flowOn to a SharedFlow has not effect. See the SharedFlow documentation on Operator Fusion.

Throws

if provided context contains Job instance.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/flow.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/flow.html index af846c34fc..2f6b67e3c8 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/flow.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/flow.html @@ -1,72 +1 @@ - - - - - flow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

flow

-
-
-
-
fun <T> flow(block: suspend FlowCollector<T>.() -> Unit): Flow<T>

Creates a cold flow from the given suspendable block. The flow being cold means that the block is called every time a terminal operator is applied to the resulting flow.

Example of usage:

fun fibonacci(): Flow<BigInteger> = flow {
var x = BigInteger.ZERO
var y = BigInteger.ONE
while (true) {
emit(x)
x = y.also {
y += x
}
}
}

fibonacci().take(100).collect { println(it) }

Emissions from flow builder are cancellable by default — each call to emit also calls ensureActive.

emit should happen strictly in the dispatchers of the block in order to preserve the flow context. For example, the following code will result in an IllegalStateException:

flow {
emit(1) // Ok
withContext(Dispatcher.IO) {
emit(2) // Will fail with ISE
}
}

If you want to switch the context of execution of a flow, use the flowOn operator.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/fold.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/fold.html index 284524eae0..7a42a7cfca 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/fold.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/fold.html @@ -1,72 +1 @@ - - - - - fold - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

fold

-
-
-
-
inline suspend fun <T, R> Flow<T>.fold(initial: R, crossinline operation: suspend (R, T) -> R): R

Accumulates value starting with initial value and applying operation current accumulator value and each element

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/get-and-update.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/get-and-update.html index e9f6c4fdb4..2b12934024 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/get-and-update.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/get-and-update.html @@ -1,72 +1 @@ - - - - - getAndUpdate - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

getAndUpdate

-
-
-
-
inline fun <T> MutableStateFlow<T>.getAndUpdate(function: (T) -> T): T

Updates the MutableStateFlow.value atomically using the specified function of its value, and returns its prior value.

function may be evaluated multiple times, if value is being concurrently updated.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/index.html index d8acd6b011..b097b106b5 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/index.html @@ -1,1600 +1 @@ - - - - - kotlinx.coroutines.flow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Package kotlinx.coroutines.flow

-
-
-

Flow — asynchronous cold stream of elements.

-
-
-
-
-

Types

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract class AbstractFlow<T> : Flow<T> , CancellableFlow<T>

Base class for stateful implementations of Flow. It tracks all the properties required for context preservation and throws an IllegalStateException if any of the properties are violated.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface Flow<out T>

An asynchronous data stream that sequentially emits values and completes normally or with an exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun interface FlowCollector<in T>

FlowCollector is used as an intermediate or a terminal collector of the flow and represents an entity that accepts values emitted by the Flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface MutableSharedFlow<T> : SharedFlow<T> , FlowCollector<T>

A mutable SharedFlow that provides functions to emit values to the flow. An instance of MutableSharedFlow with the given configuration parameters can be created using MutableSharedFlow(...) constructor function.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface MutableStateFlow<T> : StateFlow<T> , MutableSharedFlow<T>

A mutable StateFlow that provides a setter for value. An instance of MutableStateFlow with the given initial value can be created using MutableStateFlow(value) constructor function.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface SharedFlow<out T> : Flow<T>

A hotFlow that shares emitted values among all its collectors in a broadcast fashion, so that all collectors get all emitted values. A shared flow is called hot because its active instance exists independently of the presence of collectors. This is opposed to a regular Flow, such as defined by the flow { ... } function, which is cold and is started separately for each collector.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
enum SharingCommand : Enum<SharingCommand>

A command emitted by SharingStarted implementations to control the sharing coroutine in the shareIn and stateIn operators.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun interface SharingStarted

A strategy for starting and stopping the sharing coroutine in shareIn and stateIn operators.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface StateFlow<out T> : SharedFlow<T>

A SharedFlow that represents a read-only state with a single updatable data value that emits updates to the value to its collectors. A state flow is a hot flow because its active instance exists independently of the presence of collectors. Its current value can be retrieved via the value property.

-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Array<T>.asFlow(): Flow<T>
fun LongArray.asFlow(): Flow<Long>

Creates a cold flow that produces values from the given array. The flow being cold means that the array components are read every time a terminal operator is applied to the resulting flow.

fun <T> () -> T.asFlow(): Flow<T>
fun <T> suspend () -> T.asFlow(): Flow<T>

Creates a cold flow that produces a single value from the given functional type.

fun IntArray.asFlow(): Flow<Int>

Creates a cold flow that produces values from the array. The flow being cold means that the array components are read every time a terminal operator is applied to the resulting flow.

fun <T> Iterable<T>.asFlow(): Flow<T>

Creates a cold flow that produces values from the given iterable.

fun <T> Iterator<T>.asFlow(): Flow<T>

Creates a cold flow that produces values from the given iterator.

fun IntRange.asFlow(): Flow<Int>
fun LongRange.asFlow(): Flow<Long>

Creates a flow that produces values from the range.

fun <T> Sequence<T>.asFlow(): Flow<T>

Creates a cold flow that produces values from the given sequence.

fun <T> BroadcastChannel<T>.asFlow(): Flow<T>

Represents the given broadcast channel as a hot flow. Every flow collector will trigger a new broadcast channel subscription.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> MutableSharedFlow<T>.asSharedFlow(): SharedFlow<T>

Represents this mutable shared flow as a read-only shared flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> MutableStateFlow<T>.asStateFlow(): StateFlow<T>

Represents this mutable state flow as a read-only state flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.buffer(capacity: Int = BUFFERED): Flow<T>

fun <T> Flow<T>.buffer(capacity: Int = BUFFERED, onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND): Flow<T>

Buffers flow emissions via channel of a specified capacity and runs collector in a separate coroutine.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> callbackFlow(block: suspend ProducerScope<T>.() -> Unit): Flow<T>

Creates an instance of a coldFlow with elements that are sent to a SendChannel provided to the builder's block of code via ProducerScope. It allows elements to be produced by code that is running in a different context or concurrently.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.cancellable(): Flow<T>

Returns a flow which checks cancellation status on each emission and throws the corresponding cancellation cause if flow collector was cancelled. Note that flow builder and all implementations of SharedFlow are cancellable by default.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.catch(action: suspend FlowCollector<T>.(cause: Throwable) -> Unit): Flow<T>

Catches exceptions in the flow completion and calls a specified action with the caught exception. This operator is transparent to exceptions that occur in downstream flow and does not catch exceptions that are thrown to cancel the flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> channelFlow(block: suspend ProducerScope<T>.() -> Unit): Flow<T>

Creates an instance of a coldFlow with elements that are sent to a SendChannel provided to the builder's block of code via ProducerScope. It allows elements to be produced by code that is running in a different context or concurrently. The resulting flow is cold, which means that block is called every time a terminal operator is applied to the resulting flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun Flow<*>.collect()

Terminal flow operator that collects the given flow but ignores all emitted values. If any exception occurs during collect or in the provided flow, this exception is rethrown from this method.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline suspend fun <T> Flow<T>.collectIndexed(crossinline action: suspend (index: Int, T) -> Unit)

Terminal flow operator that collects the given flow with a provided action that takes the index of an element (zero-based) and the element. If any exception occurs during collect or in the provided flow, this exception is rethrown from this method.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> Flow<T>.collectLatest(action: suspend (T) -> Unit)

Terminal flow operator that collects the given flow with a provided action. The crucial difference from collect is that when the original flow emits a new value then the action block for the previous value is cancelled.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T, R> combine(vararg flows: Flow<T>, crossinline transform: suspend (Array<T>) -> R): Flow<R>
inline fun <T, R> combine(flows: Iterable<Flow<T>>, crossinline transform: suspend (Array<T>) -> R): Flow<R>
@JvmName(name = "flowCombine")
fun <T1, T2, R> Flow<T1>.combine(flow: Flow<T2>, transform: suspend (T1, T2) -> R): Flow<R>
fun <T1, T2, R> combine(    flow: Flow<T1>,     flow2: Flow<T2>,     transform: suspend (T1, T2) -> R): Flow<R>
fun <T1, T2, T3, R> combine(    flow: Flow<T1>,     flow2: Flow<T2>,     flow3: Flow<T3>,     transform: suspend (T1, T2, T3) -> R): Flow<R>
fun <T1, T2, T3, T4, R> combine(    flow: Flow<T1>,     flow2: Flow<T2>,     flow3: Flow<T3>,     flow4: Flow<T4>,     transform: suspend (T1, T2, T3, T4) -> R): Flow<R>
fun <T1, T2, T3, T4, T5, R> combine(    flow: Flow<T1>,     flow2: Flow<T2>,     flow3: Flow<T3>,     flow4: Flow<T4>,     flow5: Flow<T5>,     transform: suspend (T1, T2, T3, T4, T5) -> R): Flow<R>

Returns a Flow whose values are generated with transform function by combining the most recently emitted values by each flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T, R> combineTransform(vararg flows: Flow<T>, crossinline transform: suspend FlowCollector<R>.(Array<T>) -> Unit): Flow<R>
inline fun <T, R> combineTransform(flows: Iterable<Flow<T>>, crossinline transform: suspend FlowCollector<R>.(Array<T>) -> Unit): Flow<R>
@JvmName(name = "flowCombineTransform")
fun <T1, T2, R> Flow<T1>.combineTransform(flow: Flow<T2>, transform: suspend FlowCollector<R>.(T1, T2) -> Unit): Flow<R>
fun <T1, T2, R> combineTransform(    flow: Flow<T1>,     flow2: Flow<T2>,     transform: suspend FlowCollector<R>.(T1, T2) -> Unit): Flow<R>
fun <T1, T2, T3, R> combineTransform(    flow: Flow<T1>,     flow2: Flow<T2>,     flow3: Flow<T3>,     transform: suspend FlowCollector<R>.(T1, T2, T3) -> Unit): Flow<R>
fun <T1, T2, T3, T4, R> combineTransform(    flow: Flow<T1>,     flow2: Flow<T2>,     flow3: Flow<T3>,     flow4: Flow<T4>,     transform: suspend FlowCollector<R>.(T1, T2, T3, T4) -> Unit): Flow<R>
fun <T1, T2, T3, T4, T5, R> combineTransform(    flow: Flow<T1>,     flow2: Flow<T2>,     flow3: Flow<T3>,     flow4: Flow<T4>,     flow5: Flow<T5>,     transform: suspend FlowCollector<R>.(T1, T2, T3, T4, T5) -> Unit): Flow<R>

Returns a Flow whose values are generated by transform function that process the most recently emitted values by each flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.conflate(): Flow<T>

Conflates flow emissions via conflated channel and runs collector in a separate coroutine. The effect of this is that emitter is never suspended due to a slow collector, but collector always gets the most recent value emitted.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> ReceiveChannel<T>.consumeAsFlow(): Flow<T>

Represents the given receive channel as a hot flow and consumes the channel on the first collection from this flow. The resulting flow can be collected just once and throws IllegalStateException when trying to collect it more than once.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> Flow<T>.count(): Int

Returns the number of elements in this flow.

suspend fun <T> Flow<T>.count(predicate: suspend (T) -> Boolean): Int

Returns the number of elements matching the given predicate.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.debounce(timeoutMillis: (T) -> Long): Flow<T>
@JvmName(name = "debounceDuration")
fun <T> Flow<T>.debounce(timeout: (T) -> Duration): Flow<T>
fun <T> Flow<T>.debounce(timeoutMillis: Long): Flow<T>
fun <T> Flow<T>.debounce(timeout: Duration): Flow<T>

Returns a flow that mirrors the original flow, but filters out values that are followed by the newer values within the given timeout. The latest value is always emitted.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.distinctUntilChanged(): Flow<T>

Returns flow where all subsequent repetitions of the same value are filtered out.

fun <T> Flow<T>.distinctUntilChanged(areEquivalent: (T, T) -> Boolean): Flow<T>

Returns flow where all subsequent repetitions of the same value are filtered out, when compared with each other via the provided areEquivalent function.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T, K> Flow<T>.distinctUntilChangedBy(keySelector: (T) -> K): Flow<T>

Returns flow where all subsequent repetitions of the same key are filtered out, where key is extracted with keySelector function.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.drop(count: Int): Flow<T>

Returns a flow that ignores first count elements. Throws IllegalArgumentException if count is negative.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.dropWhile(predicate: suspend (T) -> Boolean): Flow<T>

Returns a flow containing all elements except first elements that satisfy the given predicate.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> FlowCollector<T>.emitAll(channel: ReceiveChannel<T>)

Emits all elements from the given channel to this flow collector and cancels (consumes) the channel afterwards. If you need to iterate over the channel without consuming it, a regular for loop should be used instead.

suspend fun <T> FlowCollector<T>.emitAll(flow: Flow<T>)

Collects all the values from the given flow and emits them to the collector. It is a shorthand for flow.collect { value -> emit(value) }.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> emptyFlow(): Flow<T>

Returns an empty flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T> Flow<T>.filter(crossinline predicate: suspend (T) -> Boolean): Flow<T>

Returns a flow containing only values of the original flow that match the given predicate.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <R> Flow<*>.filterIsInstance(): Flow<R>

Returns a flow containing only values that are instances of specified type R.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T> Flow<T>.filterNot(crossinline predicate: suspend (T) -> Boolean): Flow<T>

Returns a flow containing only values of the original flow that do not match the given predicate.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T : Any> Flow<T?>.filterNotNull(): Flow<T>

Returns a flow containing only values of the original flow that are not null.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> Flow<T>.first(): T

The terminal operator that returns the first element emitted by the flow and then cancels flow's collection. Throws NoSuchElementException if the flow was empty.

suspend fun <T> Flow<T>.first(predicate: suspend (T) -> Boolean): T

The terminal operator that returns the first element emitted by the flow matching the given predicate and then cancels flow's collection. Throws NoSuchElementException if the flow has not contained elements matching the predicate.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> Flow<T>.firstOrNull(): T?

The terminal operator that returns the first element emitted by the flow and then cancels flow's collection. Returns null if the flow was empty.

suspend fun <T> Flow<T>.firstOrNull(predicate: suspend (T) -> Boolean): T?

The terminal operator that returns the first element emitted by the flow matching the given predicate and then cancels flow's collection. Returns null if the flow did not contain an element matching the predicate.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T, R> Flow<T>.flatMapConcat(transform: suspend (T) -> Flow<R>): Flow<R>

Transforms elements emitted by the original flow by applying transform, that returns another flow, and then concatenating and flattening these flows.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T, R> Flow<T>.flatMapLatest(crossinline transform: suspend (T) -> Flow<R>): Flow<R>

Returns a flow that switches to a new flow produced by transform function every time the original flow emits a value. When the original flow emits a new value, the previous flow produced by transform block is cancelled.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T, R> Flow<T>.flatMapMerge(concurrency: Int = DEFAULT_CONCURRENCY, transform: suspend (T) -> Flow<R>): Flow<R>

Transforms elements emitted by the original flow by applying transform, that returns another flow, and then merging and flattening these flows.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<Flow<T>>.flattenConcat(): Flow<T>

Flattens the given flow of flows into a single flow in a sequential manner, without interleaving nested flows.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<Flow<T>>.flattenMerge(concurrency: Int = DEFAULT_CONCURRENCY): Flow<T>

Flattens the given flow of flows into a single flow with a concurrency limit on the number of concurrently collected flows.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> flow(block: suspend FlowCollector<T>.() -> Unit): Flow<T>

Creates a cold flow from the given suspendable block. The flow being cold means that the block is called every time a terminal operator is applied to the resulting flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> flowOf(value: T): Flow<T>

Creates a flow that produces the given value.

fun <T> flowOf(vararg elements: T): Flow<T>

Creates a flow that produces values from the specified vararg-arguments.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.flowOn(context: CoroutineContext): Flow<T>

Changes the context where this flow is executed to the given context. This operator is composable and affects only preceding operators that do not have its own context. This operator is context preserving: contextdoes not leak into the downstream flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline suspend fun <T, R> Flow<T>.fold(initial: R, crossinline operation: suspend (R, T) -> R): R

Accumulates value starting with initial value and applying operation current accumulator value and each element

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T> MutableStateFlow<T>.getAndUpdate(function: (T) -> T): T

Updates the MutableStateFlow.value atomically using the specified function of its value, and returns its prior value.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> Flow<T>.last(): T

The terminal operator that returns the last element emitted by the flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> Flow<T>.lastOrNull(): T?

The terminal operator that returns the last element emitted by the flow or null if the flow was empty.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.launchIn(scope: CoroutineScope): Job

Terminal flow operator that launches the collection of the given flow in the scope. It is a shorthand for scope.launch { flow.collect() }.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T, R> Flow<T>.map(crossinline transform: suspend (T) -> R): Flow<R>

Returns a flow containing the results of applying the given transform function to each value of the original flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T, R> Flow<T>.mapLatest(transform: suspend (T) -> R): Flow<R>

Returns a flow that emits elements from the original flow transformed by transform function. When the original flow emits a new value, computation of the transform block for previous value is cancelled.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T, R : Any> Flow<T>.mapNotNull(crossinline transform: suspend (T) -> R?): Flow<R>

Returns a flow that contains only non-null results of applying the given transform function to each value of the original flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Iterable<Flow<T>>.merge(): Flow<T>
fun <T> merge(vararg flows: Flow<T>): Flow<T>

Merges the given flows into a single flow without preserving an order of elements. All flows are merged concurrently, without limit on the number of simultaneously collected flows.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> MutableSharedFlow(    replay: Int = 0,     extraBufferCapacity: Int = 0,     onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND): MutableSharedFlow<T>

Creates a MutableSharedFlow with the given configuration parameters.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> MutableStateFlow(value: T): MutableStateFlow<T>

Creates a MutableStateFlow with the given initial value.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.onCompletion(action: suspend FlowCollector<T>.(cause: Throwable?) -> Unit): Flow<T>

Returns a flow that invokes the given actionafter the flow is completed or cancelled, passing the cancellation exception or failure as cause parameter of action.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.onEach(action: suspend (T) -> Unit): Flow<T>

Returns a flow that invokes the given actionbefore each value of the upstream flow is emitted downstream.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.onEmpty(action: suspend FlowCollector<T>.() -> Unit): Flow<T>

Invokes the given action when this flow completes without emitting any elements. The receiver of the action is FlowCollector, so onEmpty can emit additional elements. For example:

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.onStart(action: suspend FlowCollector<T>.() -> Unit): Flow<T>

Returns a flow that invokes the given actionbefore this flow starts to be collected.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> SharedFlow<T>.onSubscription(action: suspend FlowCollector<T>.() -> Unit): SharedFlow<T>

Returns a flow that invokes the given actionafter this shared flow starts to be collected (after the subscription is registered).

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.produceIn(scope: CoroutineScope): ReceiveChannel<T>

Creates a produce coroutine that collects the given flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> ReceiveChannel<T>.receiveAsFlow(): Flow<T>

Represents the given receive channel as a hot flow and receives from the channel in fan-out fashion every time this flow is collected. One element will be emitted to one collector only.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <S, T : S> Flow<T>.reduce(operation: suspend (S, T) -> S): S

Accumulates value starting with the first element and applying operation to current accumulator value and each element. Throws NoSuchElementException if flow was empty.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.retry(retries: Long = Long.MAX_VALUE, predicate: suspend (cause: Throwable) -> Boolean = { true }): Flow<T>

Retries collection of the given flow up to retries times when an exception that matches the given predicate occurs in the upstream flow. This operator is transparent to exceptions that occur in downstream flow and does not retry on exceptions that are thrown to cancel the flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.retryWhen(predicate: suspend FlowCollector<T>.(cause: Throwable, attempt: Long) -> Boolean): Flow<T>

Retries collection of the given flow when an exception occurs in the upstream flow and the predicate returns true. The predicate also receives an attempt number as parameter, starting from zero on the initial call. This operator is transparent to exceptions that occur in downstream flow and does not retry on exceptions that are thrown to cancel the flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T, R> Flow<T>.runningFold(initial: R, operation: suspend (R, T) -> R): Flow<R>

Folds the given flow with operation, emitting every intermediate result, including initial value. Note that initial value should be immutable (or should not be mutated) as it is shared between different collectors. For example:

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.runningReduce(operation: suspend (T, T) -> T): Flow<T>

Reduces the given flow with operation, emitting every intermediate result, including initial value. The first element is taken as initial value for operation accumulator. This operator has a sibling with initial value -- scan.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.sample(periodMillis: Long): Flow<T>
fun <T> Flow<T>.sample(period: Duration): Flow<T>

Returns a flow that emits only the latest value emitted by the original flow during the given sampling period.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T, R> Flow<T>.scan(initial: R, operation: suspend (R, T) -> R): Flow<R>

Folds the given flow with operation, emitting every intermediate result, including initial value. Note that initial value should be immutable (or should not be mutated) as it is shared between different collectors. For example:

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.shareIn(    scope: CoroutineScope,     started: SharingStarted,     replay: Int = 0): SharedFlow<T>

Converts a coldFlow into a hotSharedFlow that is started in the given coroutine scope, sharing emissions from a single running instance of the upstream flow with multiple downstream subscribers, and replaying a specified number of replay values to new subscribers. See the SharedFlow documentation for the general concepts of shared flows.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> Flow<T>.single(): T

The terminal operator that awaits for one and only one value to be emitted. Throws NoSuchElementException for empty flow and IllegalStateException for flow that contains more than one element.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> Flow<T>.singleOrNull(): T?

The terminal operator that awaits for one and only one value to be emitted. Returns the single value or null, if the flow was empty or emitted more than one value.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> Flow<T>.stateIn(scope: CoroutineScope): StateFlow<T>

Starts the upstream flow in a given scope, suspends until the first value is emitted, and returns a hotStateFlow of future emissions, sharing the most recently emitted value from this running instance of the upstream flow with multiple downstream subscribers. See the StateFlow documentation for the general concepts of state flows.

fun <T> Flow<T>.stateIn(    scope: CoroutineScope,     started: SharingStarted,     initialValue: T): StateFlow<T>

Converts a coldFlow into a hotStateFlow that is started in the given coroutine scope, sharing the most recently emitted value from a single running instance of the upstream flow with multiple downstream subscribers. See the StateFlow documentation for the general concepts of state flows.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.take(count: Int): Flow<T>

Returns a flow that contains first count elements. When count elements are consumed, the original flow is cancelled. Throws IllegalArgumentException if count is not positive.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.takeWhile(predicate: suspend (T) -> Boolean): Flow<T>

Returns a flow that contains first elements satisfying the given predicate.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T, C : MutableCollection<in T>> Flow<T>.toCollection(destination: C): C

Collects given flow into a destination

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> Flow<T>.toList(destination: MutableList<T> = ArrayList()): List<T>

Collects given flow into a destination

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> Flow<T>.toSet(destination: MutableSet<T> = LinkedHashSet()): Set<T>

Collects given flow into a destination

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T, R> Flow<T>.transform(crossinline transform: suspend FlowCollector<R>.(T) -> Unit): Flow<R>

Applies transform function to each value of the given flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T, R> Flow<T>.transformLatest(transform: suspend FlowCollector<R>.(T) -> Unit): Flow<R>

Returns a flow that produces element by transform function every time the original flow emits a value. When the original flow emits a new value, the previous transform block is cancelled, thus the name transformLatest.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T, R> Flow<T>.transformWhile(transform: suspend FlowCollector<R>.(T) -> Boolean): Flow<R>

Applies transform function to each value of the given flow while this function returns true.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T> MutableStateFlow<T>.update(function: (T) -> T)

Updates the MutableStateFlow.value atomically using the specified function of its value.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun <T> MutableStateFlow<T>.updateAndGet(function: (T) -> T): T

Updates the MutableStateFlow.value atomically using the specified function of its value, and returns the new value.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun SharingStarted.Companion.WhileSubscribed(stopTimeout: Duration = Duration.ZERO, replayExpiration: Duration = Duration.INFINITE): SharingStarted

Sharing is started when the first subscriber appears, immediately stops when the last subscriber disappears (by default), keeping the replay cache forever (by default).

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Flow<T>.withIndex(): Flow<IndexedValue<T>>

Returns a flow that wraps each element into IndexedValue, containing value and its index (starting from zero).

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T1, T2, R> Flow<T1>.zip(other: Flow<T2>, transform: suspend (T1, T2) -> R): Flow<R>

Zips values from the current flow (this) with other flow using provided transform function applied to each pair of values. The resulting flow completes as soon as one of the flows completes and cancel is called on the remaining flow.

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
val DEFAULT_CONCURRENCY: Int

Default concurrency limit that is used by flattenMerge and flatMapMerge operators. It is 16 by default and can be changed on JVM using DEFAULT_CONCURRENCY_PROPERTY_NAME property.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
const val DEFAULT_CONCURRENCY_PROPERTY_NAME: String

Name of the property that defines the value of DEFAULT_CONCURRENCY.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/last-or-null.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/last-or-null.html index c68c62e745..89087d5e4a 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/last-or-null.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/last-or-null.html @@ -1,72 +1 @@ - - - - - lastOrNull - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

lastOrNull

-
-
-
-
suspend fun <T> Flow<T>.lastOrNull(): T?

The terminal operator that returns the last element emitted by the flow or null if the flow was empty.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/last.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/last.html index 5d5d7d09db..34f024454f 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/last.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/last.html @@ -1,72 +1 @@ - - - - - last - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

last

-
-
-
-
suspend fun <T> Flow<T>.last(): T

The terminal operator that returns the last element emitted by the flow.

Throws NoSuchElementException if the flow was empty.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/launch-in.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/launch-in.html index 65d1a0299b..b6df7c195e 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/launch-in.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/launch-in.html @@ -1,72 +1 @@ - - - - - launchIn - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

launchIn

-
-
-
-
fun <T> Flow<T>.launchIn(scope: CoroutineScope): Job

Terminal flow operator that launches the collection of the given flow in the scope. It is a shorthand for scope.launch { flow.collect() }.

This operator is usually used with onEach, onCompletion and catch operators to process all emitted values handle an exception that might occur in the upstream flow or during processing, for example:

flow
.onEach { value -> updateUi(value) }
.onCompletion { cause -> updateUi(if (cause == null) "Done" else "Failed") }
.catch { cause -> LOG.error("Exception: $cause") }
.launchIn(uiScope)

Note that the resulting value of launchIn is not used and the provided scope takes care of cancellation.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/map-latest.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/map-latest.html index 8690e9cb2f..2abcc6679b 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/map-latest.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/map-latest.html @@ -1,72 +1 @@ - - - - - mapLatest - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

mapLatest

-
-
-
-
fun <T, R> Flow<T>.mapLatest(transform: suspend (T) -> R): Flow<R>

Returns a flow that emits elements from the original flow transformed by transform function. When the original flow emits a new value, computation of the transform block for previous value is cancelled.

For example, the following flow:

flow {
emit("a")
delay(100)
emit("b")
}.mapLatest { value ->
println("Started computing $value")
delay(200)
"Computed $value"
}

will print "Started computing a" and "Started computing b", but the resulting flow will contain only "Computed b" value.

This operator is buffered by default and size of its output buffer can be changed by applying subsequent buffer operator.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/map-not-null.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/map-not-null.html index e6b57d7ca4..b626b16f2c 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/map-not-null.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/map-not-null.html @@ -1,72 +1 @@ - - - - - mapNotNull - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

mapNotNull

-
-
-
-
inline fun <T, R : Any> Flow<T>.mapNotNull(crossinline transform: suspend (T) -> R?): Flow<R>

Returns a flow that contains only non-null results of applying the given transform function to each value of the original flow.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/map.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/map.html index 9dd21e926b..7b78450652 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/map.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/map.html @@ -1,72 +1 @@ - - - - - map - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

map

-
-
-
-
inline fun <T, R> Flow<T>.map(crossinline transform: suspend (T) -> R): Flow<R>

Returns a flow containing the results of applying the given transform function to each value of the original flow.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/merge.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/merge.html index 3df591bd4a..aeb5729b3c 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/merge.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/merge.html @@ -1,83 +1 @@ - - - - - merge - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

merge

-
-
-
-
fun <T> Iterable<Flow<T>>.merge(): Flow<T>
fun <T> merge(vararg flows: Flow<T>): Flow<T>

Merges the given flows into a single flow without preserving an order of elements. All flows are merged concurrently, without limit on the number of simultaneously collected flows.

Operator fusion

Applications of flowOn, buffer, and produceInafter this operator are fused with its concurrent merging so that only one properly configured channel is used for execution of merging logic.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/on-completion.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/on-completion.html index ed7c16fff7..a71ee7b0e8 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/on-completion.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/on-completion.html @@ -1,72 +1 @@ - - - - - onCompletion - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

onCompletion

-
-
-
-
fun <T> Flow<T>.onCompletion(action: suspend FlowCollector<T>.(cause: Throwable?) -> Unit): Flow<T>

Returns a flow that invokes the given actionafter the flow is completed or cancelled, passing the cancellation exception or failure as cause parameter of action.

Conceptually, onCompletion is similar to wrapping the flow collection into a finally block, for example the following imperative snippet:

try {
myFlow.collect { value ->
println(value)
}
} finally {
println("Done")
}

can be replaced with a declarative one using onCompletion:

myFlow
.onEach { println(it) }
.onCompletion { println("Done") }
.collect()

Unlike catch, this operator reports exception that occur both upstream and downstream and observe exceptions that are thrown to cancel the flow. Exception is empty if and only if the flow had fully completed successfully. Conceptually, the following code:

myFlow.collect { value ->
println(value)
}
println("Completed successfully")

can be replaced with:

myFlow
.onEach { println(it) }
.onCompletion { if (it == null) println("Completed successfully") }
.collect()

The receiver of the action is FlowCollector and this operator can be used to emit additional elements at the end if it completed successfully. For example:

flowOf("a", "b", "c")
.onCompletion { emit("Done") }
.collect { println(it) } // prints a, b, c, Done

In case of failure or cancellation, any attempt to emit additional elements throws the corresponding exception. Use catch if you need to suppress failure and replace it with emission of elements.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/on-each.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/on-each.html index 261037ccec..77c8dec208 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/on-each.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/on-each.html @@ -1,72 +1 @@ - - - - - onEach - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

onEach

-
-
-
-
fun <T> Flow<T>.onEach(action: suspend (T) -> Unit): Flow<T>

Returns a flow that invokes the given actionbefore each value of the upstream flow is emitted downstream.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/on-empty.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/on-empty.html index 092dc90a8e..9cd1d0009d 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/on-empty.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/on-empty.html @@ -1,72 +1 @@ - - - - - onEmpty - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

onEmpty

-
-
-
-
fun <T> Flow<T>.onEmpty(action: suspend FlowCollector<T>.() -> Unit): Flow<T>

Invokes the given action when this flow completes without emitting any elements. The receiver of the action is FlowCollector, so onEmpty can emit additional elements. For example:

emptyFlow<Int>().onEmpty {
emit(1)
emit(2)
}.collect { println(it) } // prints 1, 2
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/on-start.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/on-start.html index 6bbf0f0751..394b9cc5f1 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/on-start.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/on-start.html @@ -1,72 +1 @@ - - - - - onStart - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

onStart

-
-
-
-
fun <T> Flow<T>.onStart(action: suspend FlowCollector<T>.() -> Unit): Flow<T>

Returns a flow that invokes the given actionbefore this flow starts to be collected.

The action is called before the upstream flow is started, so if it is used with a SharedFlow there is no guarantee that emissions from the upstream flow that happen inside or immediately after this onStart action will be collected (see onSubscription for an alternative operator on shared flows).

The receiver of the action is FlowCollector, so onStart can emit additional elements. For example:

flowOf("a", "b", "c")
.onStart { emit("Begin") }
.collect { println(it) } // prints Begin, a, b, c
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/on-subscription.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/on-subscription.html index 30b726f80a..7d792fee1b 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/on-subscription.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/on-subscription.html @@ -1,72 +1 @@ - - - - - onSubscription - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

onSubscription

-
-
-
-
fun <T> SharedFlow<T>.onSubscription(action: suspend FlowCollector<T>.() -> Unit): SharedFlow<T>

Returns a flow that invokes the given actionafter this shared flow starts to be collected (after the subscription is registered).

The action is called before any value is emitted from the upstream flow to this subscription but after the subscription is established. It is guaranteed that all emissions to the upstream flow that happen inside or immediately after this onSubscription action will be collected by this subscription.

The receiver of the action is FlowCollector, so onSubscription can emit additional elements.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/produce-in.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/produce-in.html index ad90190059..5545b69cd4 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/produce-in.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/produce-in.html @@ -1,72 +1 @@ - - - - - produceIn - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

produceIn

-
-
-
-
fun <T> Flow<T>.produceIn(scope: CoroutineScope): ReceiveChannel<T>

Creates a produce coroutine that collects the given flow.

This transformation is stateful, it launches a produce coroutine that collects the given flow, and has the same behavior:

  • if collecting the flow throws, the channel will be closed with that exception

  • if the ReceiveChannel is cancelled, the collection of the flow will be cancelled

  • if collecting the flow completes normally, the ReceiveChannel will be closed normally

A channel with default buffer size is created. Use buffer operator on the flow before calling produceIn to specify a value other than default and to control what happens when data is produced faster than it is consumed, that is to control backpressure behavior.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/receive-as-flow.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/receive-as-flow.html index b692aa7a08..2cdabbed9a 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/receive-as-flow.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/receive-as-flow.html @@ -1,72 +1 @@ - - - - - receiveAsFlow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

receiveAsFlow

-
-
-
-
fun <T> ReceiveChannel<T>.receiveAsFlow(): Flow<T>

Represents the given receive channel as a hot flow and receives from the channel in fan-out fashion every time this flow is collected. One element will be emitted to one collector only.

See also consumeAsFlow which ensures that the resulting flow is collected just once.

Cancellation semantics

  • Flow collectors are cancelled when the original channel is closed with an exception.

  • Flow collectors complete normally when the original channel is closed normally.

  • Failure or cancellation of the flow collector does not affect the channel.

Operator fusion

Adjacent applications of flowOn, buffer, conflate, and produceIn to the result of receiveAsFlow are fused. In particular, produceIn returns the original channel. Calls to flowOn have generally no effect, unless buffer is used to explicitly request buffering.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/reduce.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/reduce.html index bf0dc0b641..634f3bfd6d 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/reduce.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/reduce.html @@ -1,72 +1 @@ - - - - - reduce - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

reduce

-
-
-
-
suspend fun <S, T : S> Flow<T>.reduce(operation: suspend (S, T) -> S): S

Accumulates value starting with the first element and applying operation to current accumulator value and each element. Throws NoSuchElementException if flow was empty.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/retry-when.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/retry-when.html index 0ae405f59c..7e10e8460a 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/retry-when.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/retry-when.html @@ -1,72 +1 @@ - - - - - retryWhen - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

retryWhen

-
-
-
-
fun <T> Flow<T>.retryWhen(predicate: suspend FlowCollector<T>.(cause: Throwable, attempt: Long) -> Boolean): Flow<T>

Retries collection of the given flow when an exception occurs in the upstream flow and the predicate returns true. The predicate also receives an attempt number as parameter, starting from zero on the initial call. This operator is transparent to exceptions that occur in downstream flow and does not retry on exceptions that are thrown to cancel the flow.

For example, the following call retries the flow forever if the error is caused by IOException, but stops after 3 retries on any other exception:

flow.retryWhen { cause, attempt -> cause is IOException || attempt < 3 }

To implement a simple retry logic with a limit on the number of retries use retry operator.

Similarly to catch operator, the predicate code has FlowCollector as a receiver and can emit values downstream. The predicate is a suspending function, so it can be used to introduce delay before retry, for example:

flow.retryWhen { cause, attempt ->
if (cause is IOException) { // retry on IOException
emit(RetryWrapperValue(e))
delay(1000) // delay for one second before retry
true
} else { // do not retry otherwise
false
}
}

See catch for more details.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/retry.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/retry.html index 2eaac1dc16..ca7162b900 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/retry.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/retry.html @@ -1,72 +1 @@ - - - - - retry - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

retry

-
-
-
-
fun <T> Flow<T>.retry(retries: Long = Long.MAX_VALUE, predicate: suspend (cause: Throwable) -> Boolean = { true }): Flow<T>

Retries collection of the given flow up to retries times when an exception that matches the given predicate occurs in the upstream flow. This operator is transparent to exceptions that occur in downstream flow and does not retry on exceptions that are thrown to cancel the flow.

See catch for details on how exceptions are caught in flows.

The default value of retries parameter is Long.MAX_VALUE. This value effectively means to retry forever. This operator is a shorthand for the following code (see retryWhen). Note that attempt is checked first and predicate is not called when it reaches the given number of retries:

retryWhen { cause, attempt -> attempt < retries && predicate(cause) }

The predicate parameter is always true by default. The predicate is a suspending function, so it can be also used to introduce delay before retry, for example:

flow.retry(3) { e ->
// retry on any IOException but also introduce delay if retrying
(e is IOException).also { if (it) delay(1000) }
}

Throws

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/running-fold.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/running-fold.html index b4d3d611ae..d0267d3d2b 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/running-fold.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/running-fold.html @@ -1,72 +1 @@ - - - - - runningFold - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

runningFold

-
-
-
-
fun <T, R> Flow<T>.runningFold(initial: R, operation: suspend (R, T) -> R): Flow<R>

Folds the given flow with operation, emitting every intermediate result, including initial value. Note that initial value should be immutable (or should not be mutated) as it is shared between different collectors. For example:

flowOf(1, 2, 3).runningFold(emptyList<Int>()) { acc, value -> acc + value }.toList()

will produce [], [1], [1, 2], [1, 2, 3].

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/running-reduce.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/running-reduce.html index 28f5d6f2ad..46d44a4b14 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/running-reduce.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/running-reduce.html @@ -1,72 +1 @@ - - - - - runningReduce - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

runningReduce

-
-
-
-
fun <T> Flow<T>.runningReduce(operation: suspend (T, T) -> T): Flow<T>

Reduces the given flow with operation, emitting every intermediate result, including initial value. The first element is taken as initial value for operation accumulator. This operator has a sibling with initial value -- scan.

For example:

flowOf(1, 2, 3, 4).runningReduce { acc, value -> acc + value }.toList()

will produce [1, 3, 6, 10]

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/sample.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/sample.html index d5123c0b63..5041a36179 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/sample.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/sample.html @@ -1,83 +1 @@ - - - - - sample - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

sample

-
-
-
-
fun <T> Flow<T>.sample(periodMillis: Long): Flow<T>

Returns a flow that emits only the latest value emitted by the original flow during the given sampling period.

Example:

flow {
repeat(10) {
emit(it)
delay(110)
}
}.sample(200)

produces the following emissions

1, 3, 5, 7, 9

Note that the latest element is not emitted if it does not fit into the sampling window.


fun <T> Flow<T>.sample(period: Duration): Flow<T>

Returns a flow that emits only the latest value emitted by the original flow during the given sampling period.

Example:

flow {
repeat(10) {
emit(it)
delay(110.milliseconds)
}
}.sample(200.milliseconds)

produces the following emissions

1, 3, 5, 7, 9

Note that the latest element is not emitted if it does not fit into the sampling window.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/scan.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/scan.html index 866c391bca..4defc5557c 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/scan.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/scan.html @@ -1,72 +1 @@ - - - - - scan - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

scan

-
-
-
-
fun <T, R> Flow<T>.scan(initial: R, operation: suspend (R, T) -> R): Flow<R>

Folds the given flow with operation, emitting every intermediate result, including initial value. Note that initial value should be immutable (or should not be mutated) as it is shared between different collectors. For example:

flowOf(1, 2, 3).scan(emptyList<Int>()) { acc, value -> acc + value }.toList()

will produce [], [1], [1, 2], [1, 2, 3].

This function is an alias to runningFold operator.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/share-in.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/share-in.html index 2a77fa5313..2617e36b14 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/share-in.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/share-in.html @@ -1,72 +1 @@ - - - - - shareIn - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

shareIn

-
-
-
-
fun <T> Flow<T>.shareIn(    scope: CoroutineScope,     started: SharingStarted,     replay: Int = 0): SharedFlow<T>

Converts a coldFlow into a hotSharedFlow that is started in the given coroutine scope, sharing emissions from a single running instance of the upstream flow with multiple downstream subscribers, and replaying a specified number of replay values to new subscribers. See the SharedFlow documentation for the general concepts of shared flows.

The starting of the sharing coroutine is controlled by the started parameter. The following options are supported.

  • Eagerly — the upstream flow is started even before the first subscriber appears. Note that in this case all values emitted by the upstream beyond the most recent values as specified by replay parameter will be immediately discarded.

  • Lazily — starts the upstream flow after the first subscriber appears, which guarantees that this first subscriber gets all the emitted values, while subsequent subscribers are only guaranteed to get the most recent replay values. The upstream flow continues to be active even when all subscribers disappear, but only the most recent replay values are cached without subscribers.

  • WhileSubscribed() — starts the upstream flow when the first subscriber appears, immediately stops when the last subscriber disappears, keeping the replay cache forever. It has additional optional configuration parameters as explained in its documentation.

  • A custom strategy can be supplied by implementing the SharingStarted interface.

The shareIn operator is useful in situations when there is a cold flow that is expensive to create and/or to maintain, but there are multiple subscribers that need to collect its values. For example, consider a flow of messages coming from a backend over the expensive network connection, taking a lot of time to establish. Conceptually, it might be implemented like this:

val backendMessages: Flow<Message> = flow {
connectToBackend() // takes a lot of time
try {
while (true) {
emit(receiveMessageFromBackend())
}
} finally {
disconnectFromBackend()
}
}

If this flow is directly used in the application, then every time it is collected a fresh connection is established, and it will take a while before messages start flowing. However, we can share a single connection and establish it eagerly like this:

val messages: SharedFlow<Message> = backendMessages.shareIn(scope, SharingStarted.Eagerly)

Now a single connection is shared between all collectors from messages, and there is a chance that the connection is already established by the time it is needed.

Upstream completion and error handling

Normal completion of the upstream flow has no effect on subscribers, and the sharing coroutine continues to run. If a strategy like SharingStarted.WhileSubscribed is used, then the upstream can get restarted again. If a special action on upstream completion is needed, then an onCompletion operator can be used before the shareIn operator to emit a special value in this case, like this:

backendMessages
.onCompletion { cause -> if (cause == null) emit(UpstreamHasCompletedMessage) }
.shareIn(scope, SharingStarted.Eagerly)

Any exception in the upstream flow terminates the sharing coroutine without affecting any of the subscribers, and will be handled by the scope in which the sharing coroutine is launched. Custom exception handling can be configured by using the catch or retry operators before the shareIn operator. For example, to retry connection on any IOException with 1 second delay between attempts, use:

val messages = backendMessages
.retry { e ->
val shallRetry = e is IOException // other exception are bugs - handle them
if (shallRetry) delay(1000)
shallRetry
}
.shareIn(scope, SharingStarted.Eagerly)

Initial value

When a special initial value is needed to signal to subscribers that the upstream is still loading the data, use the onStart operator on the upstream flow. For example:

backendMessages
.onStart { emit(UpstreamIsStartingMessage) }
.shareIn(scope, SharingStarted.Eagerly, 1) // replay one most recent message

Buffering and conflation

The shareIn operator runs the upstream flow in a separate coroutine, and buffers emissions from upstream as explained in the buffer operator's description, using a buffer of replay size or the default (whichever is larger). This default buffering can be overridden with an explicit buffer configuration by preceding the shareIn call with buffer or conflate, for example:

  • buffer(0).shareIn(scope, started, 0) — overrides the default buffer size and creates a SharedFlow without a buffer. Effectively, it configures sequential processing between the upstream emitter and subscribers, as the emitter is suspended until all subscribers process the value. Note, that the value is still immediately discarded when there are no subscribers.

  • buffer(b).shareIn(scope, started, r) — creates a SharedFlow with replay = r and extraBufferCapacity = b.

  • conflate().shareIn(scope, started, r) — creates a SharedFlow with replay = r, onBufferOverflow = DROP_OLDEST, and extraBufferCapacity = 1 when replay == 0 to support this strategy.

Operator fusion

Application of flowOn, buffer with RENDEZVOUS capacity, or cancellable operators to the resulting shared flow has no effect.

Exceptions

This function throws IllegalArgumentException on unsupported values of parameters or combinations thereof.

Parameters

scope

the coroutine scope in which sharing is started.

started

the strategy that controls when sharing is started and stopped.

replay

the number of values replayed to new subscribers (cannot be negative, defaults to zero).

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/single-or-null.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/single-or-null.html index 230a1916a2..e22f172bd4 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/single-or-null.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/single-or-null.html @@ -1,72 +1 @@ - - - - - singleOrNull - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

singleOrNull

-
-
-
-
suspend fun <T> Flow<T>.singleOrNull(): T?

The terminal operator that awaits for one and only one value to be emitted. Returns the single value or null, if the flow was empty or emitted more than one value.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/single.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/single.html index 7987bde01a..9573ebc722 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/single.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/single.html @@ -1,72 +1 @@ - - - - - single - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

single

-
-
-
-
suspend fun <T> Flow<T>.single(): T

The terminal operator that awaits for one and only one value to be emitted. Throws NoSuchElementException for empty flow and IllegalStateException for flow that contains more than one element.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/state-in.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/state-in.html index 721654c022..d95fea9668 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/state-in.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/state-in.html @@ -1,83 +1 @@ - - - - - stateIn - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

stateIn

-
-
-
-
fun <T> Flow<T>.stateIn(    scope: CoroutineScope,     started: SharingStarted,     initialValue: T): StateFlow<T>

Converts a coldFlow into a hotStateFlow that is started in the given coroutine scope, sharing the most recently emitted value from a single running instance of the upstream flow with multiple downstream subscribers. See the StateFlow documentation for the general concepts of state flows.

The starting of the sharing coroutine is controlled by the started parameter, as explained in the documentation for shareIn operator.

The stateIn operator is useful in situations when there is a cold flow that provides updates to the value of some state and is expensive to create and/or to maintain, but there are multiple subscribers that need to collect the most recent state value. For example, consider a flow of state updates coming from a backend over the expensive network connection, taking a lot of time to establish. Conceptually it might be implemented like this:

val backendState: Flow<State> = flow {
connectToBackend() // takes a lot of time
try {
while (true) {
emit(receiveStateUpdateFromBackend())
}
} finally {
disconnectFromBackend()
}
}

If this flow is directly used in the application, then every time it is collected a fresh connection is established, and it will take a while before state updates start flowing. However, we can share a single connection and establish it eagerly like this:

val state: StateFlow<State> = backendMessages.stateIn(scope, SharingStarted.Eagerly, State.LOADING)

Now, a single connection is shared between all collectors from state, and there is a chance that the connection is already established by the time it is needed.

Upstream completion and error handling

Normal completion of the upstream flow has no effect on subscribers, and the sharing coroutine continues to run. If a a strategy like SharingStarted.WhileSubscribed is used, then the upstream can get restarted again. If a special action on upstream completion is needed, then an onCompletion operator can be used before the stateIn operator to emit a special value in this case. See the shareIn operator's documentation for an example.

Any exception in the upstream flow terminates the sharing coroutine without affecting any of the subscribers, and will be handled by the scope in which the sharing coroutine is launched. Custom exception handling can be configured by using the catch or retry operators before the stateIn operator, similarly to the shareIn operator.

Operator fusion

Application of flowOn, conflate, buffer with CONFLATED or RENDEZVOUS capacity, distinctUntilChanged, or cancellable operators to a state flow has no effect.

Parameters

scope

the coroutine scope in which sharing is started.

started

the strategy that controls when sharing is started and stopped.

initialValue

the initial value of the state flow. This value is also used when the state flow is reset using the SharingStarted.WhileSubscribed strategy with the replayExpirationMillis parameter.


suspend fun <T> Flow<T>.stateIn(scope: CoroutineScope): StateFlow<T>

Starts the upstream flow in a given scope, suspends until the first value is emitted, and returns a hotStateFlow of future emissions, sharing the most recently emitted value from this running instance of the upstream flow with multiple downstream subscribers. See the StateFlow documentation for the general concepts of state flows.

Parameters

scope

the coroutine scope in which sharing is started.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/take-while.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/take-while.html index 3eee5c9b9c..794c6f8412 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/take-while.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/take-while.html @@ -1,72 +1 @@ - - - - - takeWhile - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

takeWhile

-
-
-
-
fun <T> Flow<T>.takeWhile(predicate: suspend (T) -> Boolean): Flow<T>

Returns a flow that contains first elements satisfying the given predicate.

Note, that the resulting flow does not contain the element on which the predicate returned false. See transformWhile for a more flexible operator.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/take.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/take.html index 3859dbdf02..110a7b92d8 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/take.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/take.html @@ -1,72 +1 @@ - - - - - take - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

take

-
-
-
-
fun <T> Flow<T>.take(count: Int): Flow<T>

Returns a flow that contains first count elements. When count elements are consumed, the original flow is cancelled. Throws IllegalArgumentException if count is not positive.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/to-collection.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/to-collection.html index 6745f38065..38843bdbff 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/to-collection.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/to-collection.html @@ -1,72 +1 @@ - - - - - toCollection - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

toCollection

-
-
-
-
suspend fun <T, C : MutableCollection<in T>> Flow<T>.toCollection(destination: C): C

Collects given flow into a destination

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/to-list.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/to-list.html index 422f9b1f1d..fe41189190 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/to-list.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/to-list.html @@ -1,72 +1 @@ - - - - - toList - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

toList

-
-
-
-
suspend fun <T> Flow<T>.toList(destination: MutableList<T> = ArrayList()): List<T>

Collects given flow into a destination

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/to-set.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/to-set.html index 0fd2097efa..55f1ecae01 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/to-set.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/to-set.html @@ -1,72 +1 @@ - - - - - toSet - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

toSet

-
-
-
-
suspend fun <T> Flow<T>.toSet(destination: MutableSet<T> = LinkedHashSet()): Set<T>

Collects given flow into a destination

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/transform-latest.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/transform-latest.html index 376be68ed8..5ac858644d 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/transform-latest.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/transform-latest.html @@ -1,72 +1 @@ - - - - - transformLatest - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

transformLatest

-
-
-
-
fun <T, R> Flow<T>.transformLatest(transform: suspend FlowCollector<R>.(T) -> Unit): Flow<R>

Returns a flow that produces element by transform function every time the original flow emits a value. When the original flow emits a new value, the previous transform block is cancelled, thus the name transformLatest.

For example, the following flow:

flow {
emit("a")
delay(100)
emit("b")
}.transformLatest { value ->
emit(value)
delay(200)
emit(value + "_last")
}

produces a b b_last.

This operator is buffered by default and size of its output buffer can be changed by applying subsequent buffer operator.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/transform-while.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/transform-while.html index 082992657b..4e74735210 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/transform-while.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/transform-while.html @@ -1,72 +1 @@ - - - - - transformWhile - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

transformWhile

-
-
-
-
fun <T, R> Flow<T>.transformWhile(transform: suspend FlowCollector<R>.(T) -> Boolean): Flow<R>

Applies transform function to each value of the given flow while this function returns true.

The receiver of the transformWhile is FlowCollector and thus transformWhile is a flexible function that may transform emitted element, skip it or emit it multiple times.

This operator generalizes takeWhile and can be used as a building block for other operators. For example, a flow of download progress messages can be completed when the download is done but emit this last message (unlike takeWhile):

fun Flow<DownloadProgress>.completeWhenDone(): Flow<DownloadProgress> =
transformWhile { progress ->
emit(progress) // always emit progress
!progress.isDone() // continue while download is not done
}
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/transform.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/transform.html index b64bbce7f6..1bb90038ba 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/transform.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/transform.html @@ -1,72 +1 @@ - - - - - transform - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

transform

-
-
-
-
inline fun <T, R> Flow<T>.transform(crossinline transform: suspend FlowCollector<R>.(T) -> Unit): Flow<R>

Applies transform function to each value of the given flow.

The receiver of the transform is FlowCollector and thus transform is a flexible function that may transform emitted element, skip it or emit it multiple times.

This operator generalizes filter and map operators and can be used as a building block for other operators, for example:

fun Flow<Int>.skipOddAndDuplicateEven(): Flow<Int> = transform { value ->
if (value % 2 == 0) { // Emit only even values, but twice
emit(value)
emit(value)
} // Do nothing if odd
}
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/update-and-get.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/update-and-get.html index fef5bc6f2b..00e3657b7f 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/update-and-get.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/update-and-get.html @@ -1,72 +1 @@ - - - - - updateAndGet - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

updateAndGet

-
-
-
-
inline fun <T> MutableStateFlow<T>.updateAndGet(function: (T) -> T): T

Updates the MutableStateFlow.value atomically using the specified function of its value, and returns the new value.

function may be evaluated multiple times, if value is being concurrently updated.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/update.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/update.html index 2fe0fe1578..cc56ec5ffe 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/update.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/update.html @@ -1,72 +1 @@ - - - - - update - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

update

-
-
-
-
inline fun <T> MutableStateFlow<T>.update(function: (T) -> T)

Updates the MutableStateFlow.value atomically using the specified function of its value.

function may be evaluated multiple times, if value is being concurrently updated.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/with-index.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/with-index.html index ecc3339194..5be32d5353 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/with-index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/with-index.html @@ -1,72 +1 @@ - - - - - withIndex - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

withIndex

-
-
-
-
fun <T> Flow<T>.withIndex(): Flow<IndexedValue<T>>

Returns a flow that wraps each element into IndexedValue, containing value and its index (starting from zero).

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.flow/zip.html b/kotlinx-coroutines-core/kotlinx.coroutines.flow/zip.html index 690b3e16c9..e36548cb62 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.flow/zip.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.flow/zip.html @@ -1,72 +1 @@ - - - - - zip - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

zip

-
-
-
-
fun <T1, T2, R> Flow<T1>.zip(other: Flow<T2>, transform: suspend (T1, T2) -> R): Flow<R>

Zips values from the current flow (this) with other flow using provided transform function applied to each pair of values. The resulting flow completes as soon as one of the flows completes and cancel is called on the remaining flow.

It can be demonstrated with the following example:

val flow = flowOf(1, 2, 3).onEach { delay(10) }
val flow2 = flowOf("a", "b", "c", "d").onEach { delay(15) }
flow.zip(flow2) { i, s -> i.toString() + s }.collect {
println(it) // Will print "1a 2b 3c"
}

Buffering

The upstream flow is collected sequentially in the same coroutine without any buffering, while the other flow is collected concurrently as if buffer(0) is used. See documentation in the buffer operator for explanation. You can use additional calls to the buffer operator as needed for more concurrency.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.intrinsics/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.intrinsics/index.html index 2f79a8e1f2..5e3c3cb636 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.intrinsics/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.intrinsics/index.html @@ -1,83 +1 @@ - - - - - kotlinx.coroutines.intrinsics - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Package kotlinx.coroutines.intrinsics

-
-
-

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

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> suspend () -> T.startCoroutineCancellable(completion: Continuation<T>)

Use this function to start coroutine in a cancellable way, so that it can be cancelled while waiting to be dispatched.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.intrinsics/start-coroutine-cancellable.html b/kotlinx-coroutines-core/kotlinx.coroutines.intrinsics/start-coroutine-cancellable.html index 15036cdeea..9d2bd06ac7 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.intrinsics/start-coroutine-cancellable.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.intrinsics/start-coroutine-cancellable.html @@ -1,72 +1 @@ - - - - - startCoroutineCancellable - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

startCoroutineCancellable

-
-
-
-
fun <T> suspend () -> T.startCoroutineCancellable(completion: Continuation<T>)

Use this function to start coroutine in a cancellable way, so that it can be cancelled while waiting to be dispatched.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.selects/-select-builder/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.selects/-select-builder/index.html index 44a2ca58d3..609c4de7cc 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.selects/-select-builder/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.selects/-select-builder/index.html @@ -1,132 +1 @@ - - - - - SelectBuilder - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

SelectBuilder

-
-
-
interface SelectBuilder<in R>

Scope for select invocation.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract operator fun SelectClause0.invoke(block: suspend () -> R)

Registers a clause in this select expression without additional parameters that does not select any value.

abstract operator fun <Q> SelectClause1<Q>.invoke(block: suspend (Q) -> R)

Registers clause in this select expression without additional parameters that selects value of type Q.

open operator fun <P, Q> SelectClause2<P?, Q>.invoke(block: suspend (Q) -> R)

Registers clause in this select expression with additional nullable parameter of type P with the null value for this parameter that selects value of type Q.

abstract operator fun <P, Q> SelectClause2<P, Q>.invoke(param: P, block: suspend (Q) -> R)

Registers clause in this select expression with additional parameter of type P that selects value of type Q.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun onTimeout(timeMillis: Long, block: suspend () -> R)

Clause that selects the given block after a specified timeout passes. If timeout is negative or zero, block is selected immediately.

-
-
-
-
-
-

Extensions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <R> SelectBuilder<R>.onTimeout(timeout: Duration, block: suspend () -> R)

Clause that selects the given block after the specified timeout passes. If timeout is negative or zero, block is selected immediately.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.selects/-select-builder/invoke.html b/kotlinx-coroutines-core/kotlinx.coroutines.selects/-select-builder/invoke.html index d6df3cfd31..f2b929d8f6 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.selects/-select-builder/invoke.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.selects/-select-builder/invoke.html @@ -1,105 +1 @@ - - - - - invoke - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

invoke

-
-
-
-
abstract operator fun SelectClause0.invoke(block: suspend () -> R)

Registers a clause in this select expression without additional parameters that does not select any value.


abstract operator fun <Q> SelectClause1<Q>.invoke(block: suspend (Q) -> R)

Registers clause in this select expression without additional parameters that selects value of type Q.


abstract operator fun <P, Q> SelectClause2<P, Q>.invoke(param: P, block: suspend (Q) -> R)

Registers clause in this select expression with additional parameter of type P that selects value of type Q.


open operator fun <P, Q> SelectClause2<P?, Q>.invoke(block: suspend (Q) -> R)

Registers clause in this select expression with additional nullable parameter of type P with the null value for this parameter that selects value of type Q.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.selects/-select-builder/on-timeout.html b/kotlinx-coroutines-core/kotlinx.coroutines.selects/-select-builder/on-timeout.html index 8fea359e32..b58f7f44d9 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.selects/-select-builder/on-timeout.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.selects/-select-builder/on-timeout.html @@ -1,72 +1 @@ - - - - - onTimeout - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

onTimeout

-
-
-
-
abstract fun onTimeout(timeMillis: Long, block: suspend () -> R)

Clause that selects the given block after a specified timeout passes. If timeout is negative or zero, block is selected immediately.

Note: This is an experimental api. It may be replaced with light-weight timer/timeout channels in the future.

Parameters

timeMillis

timeout time in milliseconds.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.selects/-select-clause0/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.selects/-select-clause0/index.html index fa82182f0b..3d415550f6 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.selects/-select-clause0/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.selects/-select-clause0/index.html @@ -1,77 +1 @@ - - - - - SelectClause0 - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

SelectClause0

-
-
-
interface SelectClause0

Clause for select expression without additional parameters that does not select any value.

-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.selects/-select-clause1/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.selects/-select-clause1/index.html index 3bfdf4cc70..ab6899c4f5 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.selects/-select-clause1/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.selects/-select-clause1/index.html @@ -1,77 +1 @@ - - - - - SelectClause1 - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

SelectClause1

-
-
-
interface SelectClause1<out Q>

Clause for select expression without additional parameters that selects value of type Q.

-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.selects/-select-clause2/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.selects/-select-clause2/index.html index de0975ffd1..57afcf5c06 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.selects/-select-clause2/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.selects/-select-clause2/index.html @@ -1,77 +1 @@ - - - - - SelectClause2 - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

SelectClause2

-
-
-
interface SelectClause2<in P, out Q>

Clause for select expression with additional parameter of type P that selects value of type Q.

-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.selects/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.selects/index.html index 970ba40a92..262a9b8b6e 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.selects/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.selects/index.html @@ -1,204 +1 @@ - - - - - kotlinx.coroutines.selects - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Package kotlinx.coroutines.selects

-
-
-

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

-
-
-
-
-

Types

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface SelectBuilder<in R>

Scope for select invocation.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface SelectClause0

Clause for select expression without additional parameters that does not select any value.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface SelectClause1<out Q>

Clause for select expression without additional parameters that selects value of type Q.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface SelectClause2<in P, out Q>

Clause for select expression with additional parameter of type P that selects value of type Q.

-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <R> SelectBuilder<R>.onTimeout(timeout: Duration, block: suspend () -> R)

Clause that selects the given block after the specified timeout passes. If timeout is negative or zero, block is selected immediately.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline suspend fun <R> select(crossinline builder: SelectBuilder<R>.() -> Unit): R

Waits for the result of multiple suspending functions simultaneously, which are specified using clauses in the builder scope of this select invocation. The caller is suspended until one of the clauses is either selected or fails.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline suspend fun <R> selectUnbiased(crossinline builder: SelectBuilder<R>.() -> Unit): R

Waits for the result of multiple suspending functions simultaneously like select, but in an unbiased way when multiple clauses are selectable at the same time.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline suspend fun whileSelect(crossinline builder: SelectBuilder<Boolean>.() -> Unit)

Loops while select expression returns true.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.selects/on-timeout.html b/kotlinx-coroutines-core/kotlinx.coroutines.selects/on-timeout.html index 5758d1627d..a1c4dfef98 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.selects/on-timeout.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.selects/on-timeout.html @@ -1,72 +1 @@ - - - - - onTimeout - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

onTimeout

-
-
-
-
fun <R> SelectBuilder<R>.onTimeout(timeout: Duration, block: suspend () -> R)

Clause that selects the given block after the specified timeout passes. If timeout is negative or zero, block is selected immediately.

Note: This is an experimental api. It may be replaced with light-weight timer/timeout channels in the future.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.selects/select-unbiased.html b/kotlinx-coroutines-core/kotlinx.coroutines.selects/select-unbiased.html index 26dc120990..cdb23412b0 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.selects/select-unbiased.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.selects/select-unbiased.html @@ -1,72 +1 @@ - - - - - selectUnbiased - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

selectUnbiased

-
-
-
-
inline suspend fun <R> selectUnbiased(crossinline builder: SelectBuilder<R>.() -> Unit): R

Waits for the result of multiple suspending functions simultaneously like select, but in an unbiased way when multiple clauses are selectable at the same time.

This unbiased implementation of select expression randomly shuffles the clauses before checking if they are selectable, thus ensuring that there is no statistical bias to the selection of the first clauses.

See select function description for all the other details.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.selects/select.html b/kotlinx-coroutines-core/kotlinx.coroutines.selects/select.html index fe446f4526..b0824e45fc 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.selects/select.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.selects/select.html @@ -1,72 +1 @@ - - - - - select - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

select

-
-
-
-
inline suspend fun <R> select(crossinline builder: SelectBuilder<R>.() -> Unit): R

Waits for the result of multiple suspending functions simultaneously, which are specified using clauses in the builder scope of this select invocation. The caller is suspended until one of the clauses is either selected or fails.

At most one clause is atomically selected and its block is executed. The result of the selected clause becomes the result of the select. If any clause fails, then the select invocation produces the corresponding exception. No clause is selected in this case.

This select function is biased to the first clause. When multiple clauses can be selected at the same time, the first one of them gets priority. Use selectUnbiased for an unbiased (randomized) selection among the clauses.

There is no default clause for select expression. Instead, each selectable suspending function has the corresponding non-suspending version that can be used with a regular when expression to select one of the alternatives or to perform the default (else) action if none of them can be immediately selected.

List of supported select methods

ReceiverSuspending functionSelect clause
JobjoinonJoin
DeferredawaitonAwait
SendChannelsendonSend
ReceiveChannelreceiveonReceive
ReceiveChannelreceiveCatchingonReceiveCatching
nonedelayonTimeout

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this function is suspended, this function immediately resumes with CancellationException. There is a prompt cancellation guarantee. If the job was cancelled while this function was suspended, it will not resume successfully. See suspendCancellableCoroutine documentation for low-level details.

Note that this function does not check for cancellation when it is not suspended. Use yield or CoroutineScope.isActive to periodically check for cancellation in tight loops if needed.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.selects/while-select.html b/kotlinx-coroutines-core/kotlinx.coroutines.selects/while-select.html index 3e4ff1ee57..8fabc0bcbc 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.selects/while-select.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.selects/while-select.html @@ -1,72 +1 @@ - - - - - whileSelect - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

whileSelect

-
-
-
-
inline suspend fun whileSelect(crossinline builder: SelectBuilder<Boolean>.() -> Unit)

Loops while select expression returns true.

The statement of the form:

whileSelect {
/*body*/
}

is a shortcut for:

while(select<Boolean> {
/*body*/
}) {}

**Note: This is an experimental api.** It may be replaced with a higher-performance DSL for selection from loops.
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex.html b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex.html index 525329eb89..21c3144e65 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex.html @@ -1,72 +1 @@ - - - - - Mutex - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Mutex

-
-
-
-
fun Mutex(locked: Boolean = false): Mutex

Creates a Mutex instance. The mutex created is fair: lock is granted in first come, first served order.

Parameters

locked

initial state of the mutex.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/holds-lock.html b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/holds-lock.html index e8dd5cd41a..bc77e02ea7 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/holds-lock.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/holds-lock.html @@ -1,72 +1 @@ - - - - - holdsLock - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

holdsLock

-
-
-
-
abstract fun holdsLock(owner: Any): Boolean

Checks mutex locked by owner

Return

true on mutex lock by owner, false if not locker or it is locked by different owner

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/index.html index d9647befd0..63e4493b91 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/index.html @@ -1,202 +1 @@ - - - - - Mutex - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Mutex

-
-
-
interface Mutex

Mutual exclusion for coroutines.

Mutex has two states: locked and unlocked. It is non-reentrant, that is invoking lock even from the same thread/coroutine that currently holds the lock still suspends the invoker.

JVM API note: Memory semantic of the Mutex is similar to synchronized block on JVM: An unlock on a Mutex happens-before every subsequent successful lock on that Mutex. Unsuccessful call to tryLock do not have any memory effects.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun holdsLock(owner: Any): Boolean

Checks mutex locked by owner

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract suspend fun lock(owner: Any? = null)

Locks this mutex, suspending caller while the mutex is locked.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun tryLock(owner: Any? = null): Boolean

Tries to lock this mutex, returning false if this mutex is already locked.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun unlock(owner: Any? = null)

Unlocks this mutex. Throws IllegalStateException if invoked on a mutex that is not locked or was locked with a different owner token (by identity).

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val isLocked: Boolean

Returns true when this mutex is locked.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val onLock: SelectClause2<Any?, Mutex>

Deprecated for removal without built-in replacement.

-
-
-
-
-
-

Extensions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline suspend fun <T> Mutex.withLock(owner: Any? = null, action: () -> T): T

Executes the given action under this mutex's lock.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/is-locked.html b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/is-locked.html index 63d68499a5..fc06a214e2 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/is-locked.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/is-locked.html @@ -1,72 +1 @@ - - - - - isLocked - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

isLocked

-
-
-
-
abstract val isLocked: Boolean

Returns true when this mutex is locked.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/lock.html b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/lock.html index e934e74b2d..67e995275f 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/lock.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/lock.html @@ -1,72 +1 @@ - - - - - lock - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

lock

-
-
-
-
abstract suspend fun lock(owner: Any? = null)

Locks this mutex, suspending caller while the mutex is locked.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this function is suspended, this function immediately resumes with CancellationException. There is a prompt cancellation guarantee. If the job was cancelled while this function was suspended, it will not resume successfully. See suspendCancellableCoroutine documentation for low-level details. This function releases the lock if it was already acquired by this function before the CancellationException was thrown.

Note that this function does not check for cancellation when it is not suspended. Use yield or CoroutineScope.isActive to periodically check for cancellation in tight loops if needed.

Use tryLock to try acquiring a lock without waiting.

This function is fair; suspended callers are resumed in first-in-first-out order.

Parameters

owner

Optional owner token for debugging. When owner is specified (non-null value) and this mutex is already locked with the same token (same identity), this function throws IllegalStateException.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/on-lock.html b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/on-lock.html index 54f376e169..9dc22458d5 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/on-lock.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/on-lock.html @@ -1,72 +1 @@ - - - - - onLock - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

onLock

-
-
-
-
abstract val onLock: SelectClause2<Any?, Mutex>

Deprecated for removal without built-in replacement.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/try-lock.html b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/try-lock.html index bc668d09e2..bbe1f54fe3 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/try-lock.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/try-lock.html @@ -1,72 +1 @@ - - - - - tryLock - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

tryLock

-
-
-
-
abstract fun tryLock(owner: Any? = null): Boolean

Tries to lock this mutex, returning false if this mutex is already locked.

Parameters

owner

Optional owner token for debugging. When owner is specified (non-null value) and this mutex is already locked with the same token (same identity), this function throws IllegalStateException.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/unlock.html b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/unlock.html index 2a7690e87f..5e1b9cda31 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/unlock.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-mutex/unlock.html @@ -1,72 +1 @@ - - - - - unlock - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

unlock

-
-
-
-
abstract fun unlock(owner: Any? = null)

Unlocks this mutex. Throws IllegalStateException if invoked on a mutex that is not locked or was locked with a different owner token (by identity).

Parameters

owner

Optional owner token for debugging. When owner is specified (non-null value) and this mutex was locked with the different token (by identity), this function throws IllegalStateException.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore.html b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore.html index fee2b68de6..b0d414b023 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore.html @@ -1,72 +1 @@ - - - - - Semaphore - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Semaphore

-
-
-
-
fun Semaphore(permits: Int, acquiredPermits: Int = 0): Semaphore

Creates new Semaphore instance.

Parameters

permits

the number of permits available in this semaphore.

acquiredPermits

the number of already acquired permits, should be between 0 and permits (inclusively).

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/acquire.html b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/acquire.html index b57d5c717f..3a5e0ebe48 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/acquire.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/acquire.html @@ -1,72 +1 @@ - - - - - acquire - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

acquire

-
-
-
-
abstract suspend fun acquire()

Acquires a permit from this semaphore, suspending until one is available. All suspending acquirers are processed in first-in-first-out (FIFO) order.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this function is suspended, this function immediately resumes with CancellationException. There is a prompt cancellation guarantee. If the job was cancelled while this function was suspended, it will not resume successfully. See suspendCancellableCoroutine documentation for low-level details. This function releases the semaphore if it was already acquired by this function before the CancellationException was thrown.

Note, that this function does not check for cancellation when it does not suspend. Use CoroutineScope.isActive or CoroutineScope.ensureActive to periodically check for cancellation in tight loops if needed.

Use tryAcquire to try acquire a permit of this semaphore without suspension.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/available-permits.html b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/available-permits.html index 89795c6137..4e0cfafb95 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/available-permits.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/available-permits.html @@ -1,72 +1 @@ - - - - - availablePermits - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

availablePermits

-
-
-
-
abstract val availablePermits: Int

Returns the current number of permits available in this semaphore.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/index.html index 4cdb97c407..ce800a2505 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/index.html @@ -1,168 +1 @@ - - - - - Semaphore - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Semaphore

-
-
-
interface Semaphore

A counting semaphore for coroutines that logically maintains a number of available permits. Each acquire takes a single permit or suspends until it is available. Each release adds a permit, potentially releasing a suspended acquirer. Semaphore is fair and maintains a FIFO order of acquirers.

Semaphores are mostly used to limit the number of coroutines that have an access to particular resource. Semaphore with permits = 1 is essentially a Mutex.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract suspend fun acquire()

Acquires a permit from this semaphore, suspending until one is available. All suspending acquirers are processed in first-in-first-out (FIFO) order.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun release()

Releases a permit, returning it into this semaphore. Resumes the first suspending acquirer if there is one at the point of invocation. Throws IllegalStateException if the number of release invocations is greater than the number of preceding acquire.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun tryAcquire(): Boolean

Tries to acquire a permit from this semaphore without suspension.

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val availablePermits: Int

Returns the current number of permits available in this semaphore.

-
-
-
-
-
-

Extensions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline suspend fun <T> Semaphore.withPermit(action: () -> T): T

Executes the given action, acquiring a permit from this semaphore at the beginning and releasing it after the action is completed.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/release.html b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/release.html index e6c0e559a9..2a5857886c 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/release.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/release.html @@ -1,72 +1 @@ - - - - - release - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

release

-
-
-
-
abstract fun release()

Releases a permit, returning it into this semaphore. Resumes the first suspending acquirer if there is one at the point of invocation. Throws IllegalStateException if the number of release invocations is greater than the number of preceding acquire.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/try-acquire.html b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/try-acquire.html index a4bf1e575a..ac164d06df 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/try-acquire.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.sync/-semaphore/try-acquire.html @@ -1,72 +1 @@ - - - - - tryAcquire - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

tryAcquire

-
-
-
-
abstract fun tryAcquire(): Boolean

Tries to acquire a permit from this semaphore without suspension.

Return

true if a permit was acquired, false otherwise.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.sync/index.html b/kotlinx-coroutines-core/kotlinx.coroutines.sync/index.html index 0b16d594c2..39040e75fc 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.sync/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.sync/index.html @@ -1,170 +1 @@ - - - - - kotlinx.coroutines.sync - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Package kotlinx.coroutines.sync

-
-
-

Synchronization primitives (mutex).

-
-
-
-
-

Types

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface Mutex

Mutual exclusion for coroutines.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface Semaphore

A counting semaphore for coroutines that logically maintains a number of available permits. Each acquire takes a single permit or suspends until it is available. Each release adds a permit, potentially releasing a suspended acquirer. Semaphore is fair and maintains a FIFO order of acquirers.

-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun Mutex(locked: Boolean = false): Mutex

Creates a Mutex instance. The mutex created is fair: lock is granted in first come, first served order.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun Semaphore(permits: Int, acquiredPermits: Int = 0): Semaphore

Creates new Semaphore instance.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline suspend fun <T> Mutex.withLock(owner: Any? = null, action: () -> T): T

Executes the given action under this mutex's lock.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline suspend fun <T> Semaphore.withPermit(action: () -> T): T

Executes the given action, acquiring a permit from this semaphore at the beginning and releasing it after the action is completed.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.sync/with-lock.html b/kotlinx-coroutines-core/kotlinx.coroutines.sync/with-lock.html index e3bb4c8001..716d114214 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.sync/with-lock.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.sync/with-lock.html @@ -1,72 +1 @@ - - - - - withLock - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

withLock

-
-
-
-
inline suspend fun <T> Mutex.withLock(owner: Any? = null, action: () -> T): T

Executes the given action under this mutex's lock.

Return

the return value of the action.

Parameters

owner

Optional owner token for debugging. When owner is specified (non-null value) and this mutex is already locked with the same token (same identity), this function throws IllegalStateException.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines.sync/with-permit.html b/kotlinx-coroutines-core/kotlinx.coroutines.sync/with-permit.html index 329fc67cb0..f33aaf372f 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines.sync/with-permit.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines.sync/with-permit.html @@ -1,72 +1 @@ - - - - - withPermit - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

withPermit

-
-
-
-
inline suspend fun <T> Semaphore.withPermit(action: () -> T): T

Executes the given action, acquiring a permit from this semaphore at the beginning and releasing it after the action is completed.

Return

the return value of the action.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/cancel.html b/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/cancel.html index ee8e508fe7..342400c690 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/cancel.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/cancel.html @@ -1,72 +1 @@ - - - - - cancel - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

cancel

-
-
-
-
abstract fun cancel(cause: Throwable? = null): Boolean

Cancels this continuation with an optional cancellation cause. The result is true if this continuation was cancelled as a result of this invocation, and false otherwise.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/index.html index 898a3c374c..1e88beaa54 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/index.html @@ -1,237 +1 @@ - - - - - CancellableContinuation - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CancellableContinuation

-
-
-
interface CancellableContinuation<in T> : Continuation<T>

Cancellable continuation. It is completed when resumed or cancelled. When the cancel function is explicitly invoked, this continuation immediately resumes with a CancellationException or the specified cancel cause.

An instance of CancellableContinuation is created by the suspendCancellableCoroutine function.

Cancellable continuation has three states (as subset of Job states):

StateisActiveisCompletedisCancelled
Active (initial state)truefalsefalse
Resumed (final completed state)falsetruefalse
Canceled (final completed state)falsetruetrue

Invocation of cancel transitions this continuation from active to cancelled state, while invocation of Continuation.resume or Continuation.resumeWithException transitions it from active to resumed state.

A cancelled continuation implies that it is completed.

Invocation of Continuation.resume or Continuation.resumeWithException in resumed state produces an IllegalStateException, but is ignored in cancelled state.

    +-----------+   resume    +---------+
| Active | ----------> | Resumed |
+-----------+ +---------+
|
| cancel
V
+-----------+
| Cancelled |
+-----------+
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun cancel(cause: Throwable? = null): Boolean

Cancels this continuation with an optional cancellation cause. The result is true if this continuation was cancelled as a result of this invocation, and false otherwise.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun invokeOnCancellation(handler: CompletionHandler)

Registers a handler to be synchronously invoked on cancellation (regular or exceptional) of this continuation. When the continuation is already cancelled, the handler is immediately invoked with the cancellation exception. Otherwise, the handler will be invoked as soon as this continuation is cancelled.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun resume(value: T, onCancellation: (cause: Throwable) -> Unit?)

Resumes this continuation with the specified value and calls the specified onCancellation handler when either resumed too late (when continuation was already cancelled) or, although resumed successfully (before cancellation), the coroutine's job was cancelled before it had a chance to run in its dispatcher, so that the suspended function threw an exception instead of returning this value.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun CoroutineDispatcher.resumeUndispatched(value: T)

Resumes this continuation with the specified value in the invoker thread without going through the dispatch function of the CoroutineDispatcher in the context. This function is designed to only be used by CoroutineDispatcher implementations. It should not be used in general code.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Resumes this continuation with the specified exception in the invoker thread without going through the dispatch function of the CoroutineDispatcher in the context. This function is designed to only be used by CoroutineDispatcher implementations. It should not be used in general code.

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val isActive: Boolean

Returns true when this continuation is active -- it has not completed or cancelled yet.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val isCancelled: Boolean

Returns true if this continuation was cancelled.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val isCompleted: Boolean

Returns true when this continuation has completed for any reason. A cancelled continuation is also considered complete.

-
-
-
-
-
-

Extensions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun CancellableContinuation<*>.cancelFutureOnCancellation(future: Future<*>)

Cancels a specified future when this job is cancelled. This is a shortcut for the following code with slightly more efficient implementation (one fewer object created).

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/invoke-on-cancellation.html b/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/invoke-on-cancellation.html index da5b94630b..68a056857a 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/invoke-on-cancellation.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/invoke-on-cancellation.html @@ -1,72 +1 @@ - - - - - invokeOnCancellation - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

invokeOnCancellation

-
-
-
-
abstract fun invokeOnCancellation(handler: CompletionHandler)

Registers a handler to be synchronously invoked on cancellation (regular or exceptional) of this continuation. When the continuation is already cancelled, the handler is immediately invoked with the cancellation exception. Otherwise, the handler will be invoked as soon as this continuation is cancelled.

The installed handler should not throw any exceptions. If it does, they will get caught, wrapped into a CompletionHandlerException and processed as an uncaught exception in the context of the current coroutine (see CoroutineExceptionHandler).

At most one handler can be installed on a continuation. Attempt to call invokeOnCancellation second time produces IllegalStateException.

This handler is also called when this continuation resumes normally (with a value) and then is cancelled while waiting to be dispatched. More generally speaking, this handler is called whenever the caller of suspendCancellableCoroutine is getting a CancellationException.

A typical example for invokeOnCancellation usage is given in the documentation for the suspendCancellableCoroutine function.

Note: Implementation of CompletionHandler must be fast, non-blocking, and thread-safe. This handler can be invoked concurrently with the surrounding code. There is no guarantee on the execution context in which the handler will be invoked.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/is-active.html b/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/is-active.html index d9a2355388..f6f81cb6ac 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/is-active.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/is-active.html @@ -1,72 +1 @@ - - - - - isActive - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

isActive

-
-
-
-
abstract val isActive: Boolean

Returns true when this continuation is active -- it has not completed or cancelled yet.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/is-cancelled.html b/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/is-cancelled.html index d7a8a7806f..85cbf31f71 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/is-cancelled.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/is-cancelled.html @@ -1,72 +1 @@ - - - - - isCancelled - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

isCancelled

-
-
-
-
abstract val isCancelled: Boolean

Returns true if this continuation was cancelled.

It implies that isActive is false and isCompleted is true.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/is-completed.html b/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/is-completed.html index 20b4b71538..7fac7464e9 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/is-completed.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/is-completed.html @@ -1,72 +1 @@ - - - - - isCompleted - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

isCompleted

-
-
-
-
abstract val isCompleted: Boolean

Returns true when this continuation has completed for any reason. A cancelled continuation is also considered complete.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/resume-undispatched-with-exception.html b/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/resume-undispatched-with-exception.html index bad205c666..102e1df139 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/resume-undispatched-with-exception.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/resume-undispatched-with-exception.html @@ -1,72 +1 @@ - - - - - resumeUndispatchedWithException - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

resumeUndispatchedWithException

-
-
-
-

Resumes this continuation with the specified exception in the invoker thread without going through the dispatch function of the CoroutineDispatcher in the context. This function is designed to only be used by CoroutineDispatcher implementations. It should not be used in general code.

Note: This function is experimental. Its signature general code may be changed in the future.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/resume-undispatched.html b/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/resume-undispatched.html index 337bc0a6a2..de8b49ccfd 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/resume-undispatched.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/resume-undispatched.html @@ -1,72 +1 @@ - - - - - resumeUndispatched - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

resumeUndispatched

-
-
-
-
abstract fun CoroutineDispatcher.resumeUndispatched(value: T)

Resumes this continuation with the specified value in the invoker thread without going through the dispatch function of the CoroutineDispatcher in the context. This function is designed to only be used by CoroutineDispatcher implementations. It should not be used in general code.

Note: This function is experimental. Its signature general code may be changed in the future.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/resume.html b/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/resume.html index 7e25f43eab..439c2e10b5 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/resume.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/resume.html @@ -1,72 +1 @@ - - - - - resume - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

resume

-
-
-
-
abstract fun resume(value: T, onCancellation: (cause: Throwable) -> Unit?)

Resumes this continuation with the specified value and calls the specified onCancellation handler when either resumed too late (when continuation was already cancelled) or, although resumed successfully (before cancellation), the coroutine's job was cancelled before it had a chance to run in its dispatcher, so that the suspended function threw an exception instead of returning this value.

The installed onCancellation handler should not throw any exceptions. If it does, they will get caught, wrapped into a CompletionHandlerException and processed as an uncaught exception in the context of the current coroutine (see CoroutineExceptionHandler).

This function shall be used when resuming with a resource that must be closed by code that called the corresponding suspending function, for example:

continuation.resume(resource) {
resource.close()
}

A more complete example and further details are given in the documentation for the suspendCancellableCoroutine function.

Note: The onCancellation handler must be fast, non-blocking, and thread-safe. It can be invoked concurrently with the surrounding code. There is no guarantee on the execution context of its invocation.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-cancellation-exception.html b/kotlinx-coroutines-core/kotlinx.coroutines/-cancellation-exception.html index ac3b0d8bcf..bbd1ab1459 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-cancellation-exception.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-cancellation-exception.html @@ -1,84 +1 @@ - - - - - CancellationException - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CancellationException

-
-
-
-
expect fun CancellationException(message: String?, cause: Throwable?): CancellationException
actual fun CancellationException(message: String?, cause: Throwable?): CancellationException

Creates a cancellation exception with a specified message and cause.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-cancellation-exception/-cancellation-exception.html b/kotlinx-coroutines-core/kotlinx.coroutines/-cancellation-exception/-cancellation-exception.html index 3241bd16f7..594cd0e310 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-cancellation-exception/-cancellation-exception.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-cancellation-exception/-cancellation-exception.html @@ -1,72 +1 @@ - - - - - CancellationException - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CancellationException

-
-
-
-
expect fun CancellationException(message: String?)
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-cancellation-exception/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-cancellation-exception/index.html index 736c732162..ec2f165b83 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-cancellation-exception/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-cancellation-exception/index.html @@ -1,112 +1 @@ - - - - - CancellationException - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CancellationException

-
-
-
expect open class CancellationException(message: String?) : IllegalStateException
actual typealias CancellationException = CancellationException
actual typealias CancellationException = CancellationException
actual typealias CancellationException = CancellationException
-
-
-
-
-

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
expect fun CancellationException(message: String?)
-
-
-
-
-
-

Inheritors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-closeable-coroutine-dispatcher/-closeable-coroutine-dispatcher.html b/kotlinx-coroutines-core/kotlinx.coroutines/-closeable-coroutine-dispatcher/-closeable-coroutine-dispatcher.html index fc65856e78..7c8728dec6 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-closeable-coroutine-dispatcher/-closeable-coroutine-dispatcher.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-closeable-coroutine-dispatcher/-closeable-coroutine-dispatcher.html @@ -1,96 +1 @@ - - - - - CloseableCoroutineDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CloseableCoroutineDispatcher

-
-
-
-
expect fun CloseableCoroutineDispatcher()
actual fun CloseableCoroutineDispatcher()
actual fun CloseableCoroutineDispatcher()
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-closeable-coroutine-dispatcher/close.html b/kotlinx-coroutines-core/kotlinx.coroutines/-closeable-coroutine-dispatcher/close.html index 538a1e877f..3c0ecc58fb 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-closeable-coroutine-dispatcher/close.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-closeable-coroutine-dispatcher/close.html @@ -1,96 +1 @@ - - - - - close - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

close

-
-
-
-
expect abstract fun close()

Initiate the closing sequence of the coroutine dispatcher. After a successful call to close, no new tasks will be accepted to be dispatched, but the previously dispatched tasks will be run.

Invocations of close are idempotent and thread-safe.

actual abstract fun close()
actual abstract fun close()
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-closeable-coroutine-dispatcher/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-closeable-coroutine-dispatcher/index.html index 6db70292d6..e78f4d7b83 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-closeable-coroutine-dispatcher/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-closeable-coroutine-dispatcher/index.html @@ -1,140 +1 @@ - - - - - CloseableCoroutineDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CloseableCoroutineDispatcher

-
-
-
expect abstract class CloseableCoroutineDispatcher : CoroutineDispatcher

CoroutineDispatcher that provides a method to close it, causing the rejection of any new tasks and cleanup of all underlying resources associated with the current dispatcher. Examples of closeable dispatchers are dispatchers backed by java.lang.Executor and by kotlin.native.Worker.

The CloseableCoroutineDispatcher class is not stable for inheritance in 3rd party libraries, as new methods might be added to this interface in the future, but is stable for use.

actual abstract class CloseableCoroutineDispatcher : CoroutineDispatcher
actual typealias CloseableCoroutineDispatcher = ExecutorCoroutineDispatcher
actual abstract class CloseableCoroutineDispatcher : CoroutineDispatcher
-
-
-
-
-

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
expect fun CloseableCoroutineDispatcher()
actual fun CloseableCoroutineDispatcher()
actual fun CloseableCoroutineDispatcher()
-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
expect abstract fun close()

Initiate the closing sequence of the coroutine dispatcher. After a successful call to close, no new tasks will be accepted to be dispatched, but the previously dispatched tasks will be run.

actual abstract fun close()
actual abstract fun close()
-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-completable-deferred.html b/kotlinx-coroutines-core/kotlinx.coroutines/-completable-deferred.html index be047f057a..be2cde5761 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-completable-deferred.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-completable-deferred.html @@ -1,83 +1 @@ - - - - - CompletableDeferred - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CompletableDeferred

-
-
-
-
fun <T> CompletableDeferred(parent: Job? = null): CompletableDeferred<T>

Creates a CompletableDeferred in an active state. It is optionally a child of a parent job.


fun <T> CompletableDeferred(value: T): CompletableDeferred<T>

Creates an already completedCompletableDeferred with a given value.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-completable-deferred/complete-exceptionally.html b/kotlinx-coroutines-core/kotlinx.coroutines/-completable-deferred/complete-exceptionally.html index ee7099479c..b835830c31 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-completable-deferred/complete-exceptionally.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-completable-deferred/complete-exceptionally.html @@ -1,72 +1 @@ - - - - - completeExceptionally - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

completeExceptionally

-
-
-
-
abstract fun completeExceptionally(exception: Throwable): Boolean

Completes this deferred value exceptionally with a given exception. The result is true if this deferred was completed as a result of this invocation and false otherwise (if it was already completed).

Subsequent invocations of this function have no effect and always produce false.

This function transitions this deferred into cancelled state if it was not completed or cancelled yet. However, that if this deferred has children, then it transitions into cancelling state and becomes cancelled once all its children are complete. See Job for details.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-completable-deferred/complete.html b/kotlinx-coroutines-core/kotlinx.coroutines/-completable-deferred/complete.html index 9f8d6fab33..69eede8256 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-completable-deferred/complete.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-completable-deferred/complete.html @@ -1,72 +1 @@ - - - - - complete - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

complete

-
-
-
-
abstract fun complete(value: T): Boolean

Completes this deferred value with a given value. The result is true if this deferred was completed as a result of this invocation and false otherwise (if it was already completed).

Subsequent invocations of this function have no effect and always produce false.

This function transitions this deferred into completed state if it was not completed or cancelled yet. However, if this deferred has children, then it transitions into completing state and becomes complete once all its children are complete. See Job for details.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-completable-deferred/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-completable-deferred/index.html index 572b744cb3..261bfad8a5 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-completable-deferred/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-completable-deferred/index.html @@ -1,132 +1 @@ - - - - - CompletableDeferred - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CompletableDeferred

-
-
-
interface CompletableDeferred<T> : Deferred<T>

A Deferred that can be completed via public functions complete or cancel.

Note that the complete function returns false when this deferred value is already complete or completing, while cancel returns true as long as the deferred is still cancelling and the corresponding exception is incorporated into the final completion exception.

An instance of completable deferred can be created by CompletableDeferred() function in active state.

All functions on this interface are thread-safe and can be safely invoked from concurrent coroutines without external synchronization.

The CompletableDeferred interface is not stable for inheritance in 3rd party libraries, as new methods might be added to this interface in the future, but is stable for use.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun complete(value: T): Boolean

Completes this deferred value with a given value. The result is true if this deferred was completed as a result of this invocation and false otherwise (if it was already completed).

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun completeExceptionally(exception: Throwable): Boolean

Completes this deferred value exceptionally with a given exception. The result is true if this deferred was completed as a result of this invocation and false otherwise (if it was already completed).

-
-
-
-
-
-

Extensions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> CompletableDeferred<T>.completeWith(result: Result<T>): Boolean

Completes this deferred value with the value or exception in the given result. Returns true if this deferred was completed as a result of this invocation and false otherwise (if it was already completed).

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-completable-job/complete-exceptionally.html b/kotlinx-coroutines-core/kotlinx.coroutines/-completable-job/complete-exceptionally.html index 3fe69595a6..03ba2f99ad 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-completable-job/complete-exceptionally.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-completable-job/complete-exceptionally.html @@ -1,72 +1 @@ - - - - - completeExceptionally - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

completeExceptionally

-
-
-
-
abstract fun completeExceptionally(exception: Throwable): Boolean

Completes this job exceptionally with a given exception. The result is true if this job was completed as a result of this invocation and false otherwise (if it was already completed). exception parameter is used as an additional debug information that is not handled by any exception handlers.

Subsequent invocations of this function have no effect and always produce false.

This function transitions this job into cancelled state if it was not completed or cancelled yet. However, that if this job has children, then it transitions into cancelling state and becomes cancelled once all its children are complete. See Job for details.

Its responsibility of the caller to properly handle and report the given exception, all job's children will receive a CancellationException with the exception as a cause for the sake of diagnostic.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-completable-job/complete.html b/kotlinx-coroutines-core/kotlinx.coroutines/-completable-job/complete.html index 74a9839626..025a021491 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-completable-job/complete.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-completable-job/complete.html @@ -1,72 +1 @@ - - - - - complete - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

complete

-
-
-
-
abstract fun complete(): Boolean

Completes this job. The result is true if this job was completed as a result of this invocation and false otherwise (if it was already completed).

Subsequent invocations of this function have no effect and always produce false.

This function transitions this job into completed state if it was not completed or cancelled yet. However, that if this job has children, then it transitions into completing state and becomes complete once all its children are complete. See Job for details.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-completable-job/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-completable-job/index.html index 5f00d5aa29..2d56165b23 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-completable-job/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-completable-job/index.html @@ -1,113 +1 @@ - - - - - CompletableJob - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CompletableJob

-
-
-
interface CompletableJob : Job

A job that can be completed using complete() function. It is returned by Job() and SupervisorJob() constructor functions.

All functions on this interface are thread-safe and can be safely invoked from concurrent coroutines without external synchronization.

The CompletableJob interface is not stable for inheritance in 3rd party libraries, as new methods might be added to this interface in the future, but is stable for use.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun complete(): Boolean

Completes this job. The result is true if this job was completed as a result of this invocation and false otherwise (if it was already completed).

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun completeExceptionally(exception: Throwable): Boolean

Completes this job exceptionally with a given exception. The result is true if this job was completed as a result of this invocation and false otherwise (if it was already completed). exception parameter is used as an additional debug information that is not handled by any exception handlers.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-copyable-thread-context-element/copy-for-child.html b/kotlinx-coroutines-core/kotlinx.coroutines/-copyable-thread-context-element/copy-for-child.html index 4905105107..3000efb4e0 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-copyable-thread-context-element/copy-for-child.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-copyable-thread-context-element/copy-for-child.html @@ -1,72 +1 @@ - - - - - copyForChild - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

copyForChild

-
-
-
-
abstract fun copyForChild(): CopyableThreadContextElement<S>

Returns a CopyableThreadContextElement to replace thisCopyableThreadContextElement in the child coroutine's context that is under construction if the added context does not contain an element with the same key.

This function is called on the element each time a new coroutine inherits a context containing it, and the returned value is folded into the context given to the child.

Since this method is called whenever a new coroutine is launched in a context containing this CopyableThreadContextElement, implementations are performance-sensitive.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-copyable-thread-context-element/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-copyable-thread-context-element/index.html index ec494a5bf7..728a1962c9 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-copyable-thread-context-element/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-copyable-thread-context-element/index.html @@ -1,113 +1 @@ - - - - - CopyableThreadContextElement - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CopyableThreadContextElement

-
-
-

A ThreadContextElement copied whenever a child coroutine inherits a context containing it.

When an API uses a mutableThreadLocal for consistency, a CopyableThreadContextElement can give coroutines "coroutine-safe" write access to that ThreadLocal.

A write made to a ThreadLocal with a matching CopyableThreadContextElement by a coroutine will be visible to itself and any child coroutine launched after that write.

Writes will not be visible to the parent coroutine, peer coroutines, or coroutines that happen to use the same thread. Writes made to the ThreadLocal by the parent coroutine after launching a child coroutine will not be visible to that child coroutine.

This can be used to allow a coroutine to use a mutable ThreadLocal API transparently and correctly, regardless of the coroutine's structured concurrency.

This example adapts a ThreadLocal method trace to be "coroutine local" while the method trace is in a coroutine:

class TraceContextElement(private val traceData: TraceData?) : CopyableThreadContextElement<TraceData?> {
companion object Key : CoroutineContext.Key<TraceContextElement>

override val key: CoroutineContext.Key<TraceContextElement> = Key

override fun updateThreadContext(context: CoroutineContext): TraceData? {
val oldState = traceThreadLocal.get()
traceThreadLocal.set(traceData)
return oldState
}

override fun restoreThreadContext(context: CoroutineContext, oldState: TraceData?) {
traceThreadLocal.set(oldState)
}

override fun copyForChild(): TraceContextElement {
// Copy from the ThreadLocal source of truth at child coroutine launch time. This makes
// ThreadLocal writes between resumption of the parent coroutine and the launch of the
// child coroutine visible to the child.
return TraceContextElement(traceThreadLocal.get()?.copy())
}

override fun mergeForChild(overwritingElement: CoroutineContext.Element): CoroutineContext {
// Merge operation defines how to handle situations when both
// the parent coroutine has an element in the context and
// an element with the same key was also
// explicitly passed to the child coroutine.
// If merging does not require special behavior,
// the copy of the element can be returned.
return TraceContextElement(traceThreadLocal.get()?.copy())
}
}

A coroutine using this mechanism can safely call Java code that assumes the corresponding thread local element's value is installed into the target thread local.

Reentrancy and thread-safety

Correct implementations of this interface must expect that calls to restoreThreadContext may happen in parallel to the subsequent updateThreadContext and restoreThreadContext operations.

Even though an element is copied for each child coroutine, an implementation should be able to handle the following interleaving when a coroutine with the corresponding element is launched on a multithreaded dispatcher:

coroutine.updateThreadContext() // Thread #1
... coroutine body ...
// suspension + immediate dispatch happen here
coroutine.updateThreadContext() // Thread #2, coroutine is already resumed
// ... coroutine body after suspension point on Thread #2 ...
coroutine.restoreThreadContext() // Thread #1, is invoked late because Thread #1 is slow
coroutine.restoreThreadContext() // Thread #2, may happen in parallel with the previous restore

All implementations of CopyableThreadContextElement should be thread-safe and guard their internal mutable state within an element accordingly.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun copyForChild(): CopyableThreadContextElement<S>

Returns a CopyableThreadContextElement to replace thisCopyableThreadContextElement in the child coroutine's context that is under construction if the added context does not contain an element with the same key.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun mergeForChild(overwritingElement: CoroutineContext.Element): CoroutineContext

Returns a CopyableThreadContextElement to replace thisCopyableThreadContextElement in the child coroutine's context that is under construction if the added context does contain an element with the same key.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-copyable-thread-context-element/merge-for-child.html b/kotlinx-coroutines-core/kotlinx.coroutines/-copyable-thread-context-element/merge-for-child.html index 7cef0f016d..f3fba15f65 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-copyable-thread-context-element/merge-for-child.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-copyable-thread-context-element/merge-for-child.html @@ -1,72 +1 @@ - - - - - mergeForChild - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

mergeForChild

-
-
-
-
abstract fun mergeForChild(overwritingElement: CoroutineContext.Element): CoroutineContext

Returns a CopyableThreadContextElement to replace thisCopyableThreadContextElement in the child coroutine's context that is under construction if the added context does contain an element with the same key.

This method is invoked on the original element, accepting as the parameter the element that is supposed to overwrite it.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-copyable-throwable/create-copy.html b/kotlinx-coroutines-core/kotlinx.coroutines/-copyable-throwable/create-copy.html index 2824111a68..faa65acbb2 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-copyable-throwable/create-copy.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-copyable-throwable/create-copy.html @@ -1,72 +1 @@ - - - - - createCopy - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

createCopy

-
-
-
-
abstract fun createCopy(): T?

Creates a copy of the current instance.

For better debuggability, it is recommended to use original exception as cause of the resulting one. Stacktrace of copied exception will be overwritten by stacktrace recovery machinery by Throwable.setStackTrace call. An exception can opt-out of copying by returning null from this function. Suppressed exceptions of the original exception should not be copied in order to avoid circular exceptions.

This function is allowed to create a copy with a modified message, but it should be noted that the copy can be later recovered as well and message modification code should handle this situation correctly (e.g. by also storing the original message and checking it) to produce a human-readable result.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-copyable-throwable/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-copyable-throwable/index.html index 36d764bdfa..1cf62b0837 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-copyable-throwable/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-copyable-throwable/index.html @@ -1,109 +1 @@ - - - - - CopyableThrowable - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CopyableThrowable

-
-
-
interface CopyableThrowable<T : Throwable, CopyableThrowable<T>>

Throwable which can be cloned during stacktrace recovery in a class-specific way. For additional information about stacktrace recovery see STACKTRACE_RECOVERY_PROPERTY_NAME

Example of usage:

class BadResponseCodeException(val responseCode: Int) : Exception(), CopyableThrowable<BadResponseCodeException> {

override fun createCopy(): BadResponseCodeException {
val result = BadResponseCodeException(responseCode)
result.initCause(this)
return result
}

Copy mechanism is used only on JVM, but it might be convenient to implement it in common exceptions, so on JVM their stacktraces will be properly recovered.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun createCopy(): T?

Creates a copy of the current instance.

-
-
-
-
-
-

Inheritors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/-coroutine-dispatcher.html b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/-coroutine-dispatcher.html index 6cf382570c..eb18704373 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/-coroutine-dispatcher.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/-coroutine-dispatcher.html @@ -1,72 +1 @@ - - - - - CoroutineDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CoroutineDispatcher

-
-
-
-
fun CoroutineDispatcher()
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/dispatch.html b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/dispatch.html index 9b67cbe25e..ea6e54d25c 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/dispatch.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/dispatch.html @@ -1,72 +1 @@ - - - - - dispatch - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

dispatch

-
-
-
-
abstract fun dispatch(context: CoroutineContext, block: Runnable)

Dispatches execution of a runnable block onto another thread in the given context. This method should guarantee that the given block will be eventually invoked, otherwise the system may reach a deadlock state and never leave it. Cancellation mechanism is transparent for CoroutineDispatcher and is managed by block internals.

This method should generally be exception-safe. An exception thrown from this method may leave the coroutines that use this dispatcher in the inconsistent and hard to debug state.

This method must not immediately call block. Doing so would result in StackOverflowError when yield is repeatedly called from a loop. However, an implementation that returns false from isDispatchNeeded can delegate this function to dispatch method of Dispatchers.Unconfined, which is integrated with yield to avoid this problem.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html index 2fd0a2401a..0709c215a8 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html @@ -1,257 +1 @@ - - - - - CoroutineDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CoroutineDispatcher

-
-
-

Base class to be extended by all coroutine dispatcher implementations.

The following standard implementations are provided by kotlinx.coroutines as properties on the Dispatchers object:

  • Dispatchers.Default — is used by all standard builders if no dispatcher or any other ContinuationInterceptor is specified in their context. It uses a common pool of shared background threads. This is an appropriate choice for compute-intensive coroutines that consume CPU resources.

  • Dispatchers.IO — uses a shared pool of on-demand created threads and is designed for offloading of IO-intensive blocking operations (like file I/O and blocking socket I/O).

  • Dispatchers.Unconfined — starts coroutine execution in the current call-frame until the first suspension, whereupon the coroutine builder function returns. The coroutine will later resume in whatever thread used by the corresponding suspending function, without confining it to any specific thread or pool. The Unconfined dispatcher should not normally be used in code.

  • Private thread pools can be created with newSingleThreadContext and newFixedThreadPoolContext.

  • An arbitrary java.util.concurrent.Executor can be converted to a dispatcher with the asCoroutineDispatcher extension function.

This class ensures that debugging facilities in newCoroutineContext function work properly.

-
-
-
-
-

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun CoroutineDispatcher()
-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun dispatch(context: CoroutineContext, block: Runnable)

Dispatches execution of a runnable block onto another thread in the given context. This method should guarantee that the given block will be eventually invoked, otherwise the system may reach a deadlock state and never leave it. Cancellation mechanism is transparent for CoroutineDispatcher and is managed by block internals.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
override fun <T> interceptContinuation(continuation: Continuation<T>): Continuation<T>

Returns a continuation that wraps the provided continuation, thus intercepting all resumptions.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
open fun isDispatchNeeded(context: CoroutineContext): Boolean

Returns true if the execution of the coroutine should be performed with dispatch method. The default behavior for most dispatchers is to return true.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
open fun limitedParallelism(parallelism: Int): CoroutineDispatcher

Creates a view of the current dispatcher that limits the parallelism to the given value. The resulting view uses the original dispatcher for execution, but with the guarantee that no more than parallelism coroutines are executed at the same time.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
override fun releaseInterceptedContinuation(continuation: Continuation<*>)
-
-
-
-
-
-

Inheritors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Extensions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun CoroutineDispatcher.asExecutor(): Executor

Converts an instance of CoroutineDispatcher to an implementation of Executor.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline suspend operator fun <T> CoroutineDispatcher.invoke(noinline block: suspend CoroutineScope.() -> T): T

Calls the specified suspending block with the given CoroutineDispatcher, suspends until it completes, and returns the result.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/intercept-continuation.html b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/intercept-continuation.html index 91efc0bb40..ab653f1980 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/intercept-continuation.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/intercept-continuation.html @@ -1,72 +1 @@ - - - - - interceptContinuation - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

interceptContinuation

-
-
-
-
override fun <T> interceptContinuation(continuation: Continuation<T>): Continuation<T>

Returns a continuation that wraps the provided continuation, thus intercepting all resumptions.

This method should generally be exception-safe. An exception thrown from this method may leave the coroutines that use this dispatcher in the inconsistent and hard to debug state.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/is-dispatch-needed.html b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/is-dispatch-needed.html index 9aaddc8c86..dcc58d112d 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/is-dispatch-needed.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/is-dispatch-needed.html @@ -1,72 +1 @@ - - - - - isDispatchNeeded - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

isDispatchNeeded

-
-
-
-
open fun isDispatchNeeded(context: CoroutineContext): Boolean

Returns true if the execution of the coroutine should be performed with dispatch method. The default behavior for most dispatchers is to return true.

If this method returns false, the coroutine is resumed immediately in the current thread, potentially forming an event-loop to prevent stack overflows. The event loop is an advanced topic and its implications can be found in Dispatchers.Unconfined documentation.

A dispatcher can override this method to provide a performance optimization and avoid paying a cost of an unnecessary dispatch. E.g. MainCoroutineDispatcher.immediate checks whether we are already in the required UI thread in this method and avoids an additional dispatch when it is not required.

While this approach can be more efficient, it is not chosen by default to provide a consistent dispatching behaviour so that users won't observe unexpected and non-consistent order of events by default.

Coroutine builders like launch and async accept an optional CoroutineStart parameter that allows one to optionally choose the undispatched behavior to start coroutine immediately, but to be resumed only in the provided dispatcher.

This method should generally be exception-safe. An exception thrown from this method may leave the coroutines that use this dispatcher in the inconsistent and hard to debug state.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/limited-parallelism.html b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/limited-parallelism.html index 1d3d77b805..8fbbc22d26 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/limited-parallelism.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/limited-parallelism.html @@ -1,72 +1 @@ - - - - - limitedParallelism - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

limitedParallelism

-
-
-
-
open fun limitedParallelism(parallelism: Int): CoroutineDispatcher

Creates a view of the current dispatcher that limits the parallelism to the given value. The resulting view uses the original dispatcher for execution, but with the guarantee that no more than parallelism coroutines are executed at the same time.

This method does not impose restrictions on the number of views or the total sum of parallelism values, each view controls its own parallelism independently with the guarantee that the effective parallelism of all views cannot exceed the actual parallelism of the original dispatcher.

Limitations

The default implementation of limitedParallelism does not support direct dispatchers, such as executing the given runnable in place during dispatch calls. Any dispatcher that may return false from isDispatchNeeded is considered direct. For direct dispatchers, it is recommended to override this method and provide a domain-specific implementation or to throw an UnsupportedOperationException.

Example of usage

private val backgroundDispatcher = newFixedThreadPoolContext(4, "App Background")
// At most 2 threads will be processing images as it is really slow and CPU-intensive
private val imageProcessingDispatcher = backgroundDispatcher.limitedParallelism(2)
// At most 3 threads will be processing JSON to avoid image processing starvation
private val jsonProcessingDispatcher = backgroundDispatcher.limitedParallelism(3)
// At most 1 thread will be doing IO
private val fileWriterDispatcher = backgroundDispatcher.limitedParallelism(1)

Note how in this example the application has an executor with 4 threads, but the total sum of all limits is 6. Still, at most 4 coroutines can be executed simultaneously as each view limits only its own parallelism.

Note that this example was structured in such a way that it illustrates the parallelism guarantees. In practice, it is usually better to use Dispatchers.IO or Dispatchers.Default instead of creating a backgroundDispatcher. It is both possible and advised to call limitedParallelism on them.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/release-intercepted-continuation.html b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/release-intercepted-continuation.html index b30f57ff18..2e4b1115be 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/release-intercepted-continuation.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/release-intercepted-continuation.html @@ -1,72 +1 @@ - - - - - releaseInterceptedContinuation - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

releaseInterceptedContinuation

-
-
-
-
override fun releaseInterceptedContinuation(continuation: Continuation<*>)
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-exception-handler.html b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-exception-handler.html index 91dea2449b..a57fce4d81 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-exception-handler.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-exception-handler.html @@ -1,72 +1 @@ - - - - - CoroutineExceptionHandler - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CoroutineExceptionHandler

-
-
-
-
inline fun CoroutineExceptionHandler(crossinline handler: (CoroutineContext, Throwable) -> Unit): CoroutineExceptionHandler

Creates a CoroutineExceptionHandler instance.

Parameters

handler

a function which handles exception thrown by a coroutine

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-exception-handler/-key/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-exception-handler/-key/index.html index 339e28949a..5400c11d61 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-exception-handler/-key/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-exception-handler/-key/index.html @@ -1,77 +1 @@ - - - - - Key - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Key

-
-
-
object Key : CoroutineContext.Key<CoroutineExceptionHandler>

Key for CoroutineExceptionHandler instance in the coroutine context.

-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-exception-handler/handle-exception.html b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-exception-handler/handle-exception.html index dc2fa5ec4e..d1fb830270 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-exception-handler/handle-exception.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-exception-handler/handle-exception.html @@ -1,72 +1 @@ - - - - - handleException - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

handleException

-
-
-
-
abstract fun handleException(context: CoroutineContext, exception: Throwable)

Handles uncaught exception in the given context. It is invoked if coroutine has an uncaught exception.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-exception-handler/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-exception-handler/index.html index 8147c43014..535234d6db 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-exception-handler/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-exception-handler/index.html @@ -1,115 +1 @@ - - - - - CoroutineExceptionHandler - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CoroutineExceptionHandler

-
-
-
interface CoroutineExceptionHandler : CoroutineContext.Element

An optional element in the coroutine context to handle uncaught exceptions.

Normally, uncaught exceptions can only result from root coroutines created using the launch builder. All children coroutines (coroutines created in the context of another Job) delegate handling of their exceptions to their parent coroutine, which also delegates to the parent, and so on until the root, so the CoroutineExceptionHandler installed in their context is never used. Coroutines running with SupervisorJob do not propagate exceptions to their parent and are treated like root coroutines. A coroutine that was created using async always catches all its exceptions and represents them in the resulting Deferred object, so it cannot result in uncaught exceptions.

Handling coroutine exceptions

CoroutineExceptionHandler is a last-resort mechanism for global "catch all" behavior. You cannot recover from the exception in the CoroutineExceptionHandler. The coroutine had already completed with the corresponding exception when the handler is called. Normally, the handler is used to log the exception, show some kind of error message, terminate, and/or restart the application.

If you need to handle exception in a specific part of the code, it is recommended to use try/catch around the corresponding code inside your coroutine. This way you can prevent completion of the coroutine with the exception (exception is now caught), retry the operation, and/or take other arbitrary actions:

scope.launch { // launch child coroutine in a scope
try {
// do something
} catch (e: Throwable) {
// handle exception
}
}

Implementation details

By default, when no handler is installed, uncaught exception are handled in the following way:

  • If exception is CancellationException then it is ignored (because that is the supposed mechanism to cancel the running coroutine)

  • Otherwise:

    • if there is a Job in the context, then Job.cancel is invoked;

    • Otherwise, all instances of CoroutineExceptionHandler found via ServiceLoader

    • and current thread's Thread.uncaughtExceptionHandler are invoked.

CoroutineExceptionHandler can be invoked from an arbitrary thread.

-
-
-
-
-

Types

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
object Key : CoroutineContext.Key<CoroutineExceptionHandler>

Key for CoroutineExceptionHandler instance in the coroutine context.

-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun handleException(context: CoroutineContext, exception: Throwable)

Handles uncaught exception in the given context. It is invoked if coroutine has an uncaught exception.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-name/-coroutine-name.html b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-name/-coroutine-name.html index 2e2f52ab05..9650bdcecf 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-name/-coroutine-name.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-name/-coroutine-name.html @@ -1,72 +1 @@ - - - - - CoroutineName - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CoroutineName

-
-
-
-
fun CoroutineName(name: String)
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-name/-key/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-name/-key/index.html index bf55c87ef5..85b093d763 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-name/-key/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-name/-key/index.html @@ -1,77 +1 @@ - - - - - Key - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Key

-
-
-
object Key : CoroutineContext.Key<CoroutineName>

Key for CoroutineName instance in the coroutine context.

-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-name/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-name/index.html index 34eeebc188..5dd25be4dd 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-name/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-name/index.html @@ -1,153 +1 @@ - - - - - CoroutineName - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CoroutineName

-
-
-
data class CoroutineName(val name: String) : AbstractCoroutineContextElement

User-specified name of coroutine. This name is used in debugging mode. See newCoroutineContext for the description of coroutine debugging facilities.

-
-
-
-
-

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun CoroutineName(name: String)
-
-
-
-
-
-

Types

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
object Key : CoroutineContext.Key<CoroutineName>

Key for CoroutineName instance in the coroutine context.

-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
open override fun toString(): String

Returns a string representation of the object.

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
val name: String

User-defined coroutine name.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-name/name.html b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-name/name.html index 0d4e372000..8f60747861 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-name/name.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-name/name.html @@ -1,72 +1 @@ - - - - - name - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

name

-
-
-
-
val name: String

User-defined coroutine name.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-name/to-string.html b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-name/to-string.html index bc2e50f282..991bf0f7e1 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-name/to-string.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-name/to-string.html @@ -1,72 +1 @@ - - - - - toString - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

toString

-
-
-
-
open override fun toString(): String

Returns a string representation of the object.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope.html b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope.html index ef974ea063..7a34c89980 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope.html @@ -1,72 +1 @@ - - - - - CoroutineScope - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CoroutineScope

-
-
-
-
fun CoroutineScope(context: CoroutineContext): CoroutineScope

Creates a CoroutineScope that wraps the given coroutine context.

If the given context does not contain a Job element, then a default Job() is created. This way, failure of any child coroutine in this scope or cancellation of the scope itself cancels all the scope's children, just like inside coroutineScope block.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/coroutine-context.html b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/coroutine-context.html index d31b83464f..293284be65 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/coroutine-context.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/coroutine-context.html @@ -1,72 +1 @@ - - - - - coroutineContext - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

coroutineContext

-
-
-
-
abstract val coroutineContext: CoroutineContext

The context of this scope. Context is encapsulated by the scope and used for implementation of coroutine builders that are extensions on the scope. Accessing this property in general code is not recommended for any purposes except accessing the Job instance for advanced usages.

By convention, should contain an instance of a job to enforce structured concurrency.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html index f8d2adcdd7..d004c002f9 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html @@ -1,323 +1 @@ - - - - - CoroutineScope - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CoroutineScope

-
-
-
interface CoroutineScope

Defines a scope for new coroutines. Every coroutine builder (like launch, async, etc.) is an extension on CoroutineScope and inherits its coroutineContext to automatically propagate all its elements and cancellation.

The best ways to obtain a standalone instance of the scope are CoroutineScope() and MainScope() factory functions, taking care to cancel these coroutine scopes when they are no longer needed (see section on custom usage below for explanation and example).

Additional context elements can be appended to the scope using the plus operator.

Convention for structured concurrency

Manual implementation of this interface is not recommended, implementation by delegation should be preferred instead. By convention, the context of a scope should contain an instance of a job to enforce the discipline of structured concurrency with propagation of cancellation.

Every coroutine builder (like launch, async, and others) and every scoping function (like coroutineScope and withContext) provides its own scope with its own Job instance into the inner block of code it runs. By convention, they all wait for all the coroutines inside their block to complete before completing themselves, thus enforcing the structured concurrency. See Job documentation for more details.

Android usage

Android has first-party support for coroutine scope in all entities with the lifecycle. See the corresponding documentation.

Custom usage

CoroutineScope should be declared as a property on entities with a well-defined lifecycle that are responsible for launching child coroutines. The corresponding instance of CoroutineScope shall be created with either CoroutineScope() or MainScope():

  • CoroutineScope() uses the context provided to it as a parameter for its coroutines and adds a Job if one is not provided as part of the context.

  • MainScope() uses Dispatchers.Main for its coroutines and has a SupervisorJob.

The key part of custom usage of CoroutineScope is cancelling it at the end of the lifecycle. The CoroutineScope.cancel extension function shall be used when the entity that was launching coroutines is no longer needed. It cancels all the coroutines that might still be running on behalf of it.

For example:

class MyUIClass {
val scope = MainScope() // the scope of MyUIClass, uses Dispatchers.Main

fun destroy() { // destroys an instance of MyUIClass
scope.cancel() // cancels all coroutines launched in this scope
// ... do the rest of cleanup here ...
}

/*
* Note: if this instance is destroyed or any of the launched coroutines
* in this method throws an exception, then all nested coroutines are cancelled.
*/
fun showSomeData() = scope.launch { // launched in the main thread
// ... here we can use suspending functions or coroutine builders with other dispatchers
draw(data) // draw in the main thread
}
}
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val coroutineContext: CoroutineContext

The context of this scope. Context is encapsulated by the scope and used for implementation of coroutine builders that are extensions on the scope. Accessing this property in general code is not recommended for any purposes except accessing the Job instance for advanced usages.

-
-
-
-
-
-

Inheritors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Extensions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <E> CoroutineScope.actor(    context: CoroutineContext = EmptyCoroutineContext,     capacity: Int = 0,     start: CoroutineStart = CoroutineStart.DEFAULT,     onCompletion: CompletionHandler? = null,     block: suspend ActorScope<E>.() -> Unit): SendChannel<E>

Launches new coroutine that is receiving messages from its mailbox channel and returns a reference to its mailbox channel as a SendChannel. The resulting object can be used to send messages to this coroutine.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> CoroutineScope.async(    context: CoroutineContext = EmptyCoroutineContext,     start: CoroutineStart = CoroutineStart.DEFAULT,     block: suspend CoroutineScope.() -> T): Deferred<T>

Creates a coroutine and returns its future result as an implementation of Deferred. The running coroutine is cancelled when the resulting deferred is cancelled. The resulting coroutine has a key difference compared with similar primitives in other languages and frameworks: it cancels the parent job (or outer scope) on failure to enforce structured concurrency paradigm. To change that behaviour, supervising parent (SupervisorJob or supervisorScope) can be used.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <E> CoroutineScope.broadcast(    context: CoroutineContext = EmptyCoroutineContext,     capacity: Int = 1,     start: CoroutineStart = CoroutineStart.LAZY,     onCompletion: CompletionHandler? = null,     block: suspend ProducerScope<E>.() -> Unit): BroadcastChannel<E>

Launches new coroutine to produce a stream of values by sending them to a broadcast channel and returns a reference to the coroutine as a BroadcastChannel. The resulting object can be used to subscribe to elements produced by this coroutine.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun CoroutineScope.cancel(cause: CancellationException? = null)

Cancels this scope, including its job and all its children with an optional cancellation cause. A cause can be used to specify an error message or to provide other details on a cancellation reason for debugging purposes. Throws IllegalStateException if the scope does not have a job in it.

fun CoroutineScope.cancel(message: String, cause: Throwable? = null)

Cancels this scope, including its job and all its children with a specified diagnostic error message. A cause can be specified to provide additional details on a cancellation reason for debugging purposes. Throws IllegalStateException if the scope does not have a job in it.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun CoroutineScope.ensureActive()

Ensures that current scope is active.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
val CoroutineScope.isActive: Boolean

Returns true when the current Job is still active (has not completed and was not cancelled yet).

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun CoroutineScope.launch(    context: CoroutineContext = EmptyCoroutineContext,     start: CoroutineStart = CoroutineStart.DEFAULT,     block: suspend CoroutineScope.() -> Unit): Job

Launches a new coroutine without blocking the current thread and returns a reference to the coroutine as a Job. The coroutine is cancelled when the resulting job is cancelled.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
expect fun CoroutineScope.newCoroutineContext(context: CoroutineContext): CoroutineContext

Creates a context for a new coroutine. It installs Dispatchers.Default when no other dispatcher or ContinuationInterceptor is specified and adds optional support for debugging facilities (when turned on) and copyable-thread-local facilities on JVM.

actual fun CoroutineScope.newCoroutineContext(context: CoroutineContext): CoroutineContext

Creates a context for a new coroutine. It installs Dispatchers.Default when no other dispatcher or ContinuationInterceptor is specified and adds optional support for debugging facilities (when turned on) and copyable-thread-local facilities on JVM. See DEBUG_PROPERTY_NAME for description of debugging facilities on JVM.

actual fun CoroutineScope.newCoroutineContext(context: CoroutineContext): CoroutineContext
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
operator fun CoroutineScope.plus(context: CoroutineContext): CoroutineScope

Adds the specified coroutine context to this scope, overriding existing elements in the current scope's context with the corresponding keys.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <E> CoroutineScope.produce(    context: CoroutineContext = EmptyCoroutineContext,     capacity: Int = 0,     block: suspend ProducerScope<E>.() -> Unit): ReceiveChannel<E>

Launches a new coroutine to produce a stream of values by sending them to a channel and returns a reference to the coroutine as a ReceiveChannel. This resulting object can be used to receive elements produced by this coroutine.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> CoroutineScope.promise(    context: CoroutineContext = EmptyCoroutineContext,     start: CoroutineStart = CoroutineStart.DEFAULT,     block: suspend CoroutineScope.() -> T): Promise<T>

Starts new coroutine and returns its result as an implementation of Promise.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-start/-a-t-o-m-i-c/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-start/-a-t-o-m-i-c/index.html index e05874bdd4..f25846d240 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-start/-a-t-o-m-i-c/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-start/-a-t-o-m-i-c/index.html @@ -1,63 +1 @@ - - - - - ATOMIC - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

ATOMIC

-
-
-

Atomically (i.e., in a non-cancellable way) schedules the coroutine for execution according to its context. This is similar to DEFAULT, but the coroutine cannot be cancelled before it starts executing.

Cancellability of coroutine at suspension points depends on the particular implementation details of suspending functions as in DEFAULT.

-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-start/-d-e-f-a-u-l-t/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-start/-d-e-f-a-u-l-t/index.html index ebafe8971d..ee3320e4a0 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-start/-d-e-f-a-u-l-t/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-start/-d-e-f-a-u-l-t/index.html @@ -1,63 +1 @@ - - - - - DEFAULT - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

DEFAULT

-
-
-

Default -- immediately schedules the coroutine for execution according to its context.

If the CoroutineDispatcher of the coroutine context returns true from CoroutineDispatcher.isDispatchNeeded function as most dispatchers do, then the coroutine code is dispatched for execution later, while the code that invoked the coroutine builder continues execution.

Note that Dispatchers.Unconfined always returns false from its CoroutineDispatcher.isDispatchNeeded function, so starting a coroutine with Dispatchers.Unconfined by DEFAULT is the same as using UNDISPATCHED.

If coroutine Job is cancelled before it even had a chance to start executing, then it will not start its execution at all, but will complete with an exception.

Cancellability of a coroutine at suspension points depends on the particular implementation details of suspending functions. Use suspendCancellableCoroutine to implement cancellable suspending functions.

-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-start/-l-a-z-y/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-start/-l-a-z-y/index.html index e110fc482e..2b42f6e678 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-start/-l-a-z-y/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-start/-l-a-z-y/index.html @@ -1,63 +1 @@ - - - - - LAZY - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

LAZY

-
-
-

Starts the coroutine lazily, only when it is needed.

See the documentation for the corresponding coroutine builders for details (like launch and async).

If coroutine Job is cancelled before it even had a chance to start executing, then it will not start its execution at all, but will complete with an exception.

-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-start/-u-n-d-i-s-p-a-t-c-h-e-d/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-start/-u-n-d-i-s-p-a-t-c-h-e-d/index.html index 575cb7b8e5..25eaf8cfe6 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-start/-u-n-d-i-s-p-a-t-c-h-e-d/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-start/-u-n-d-i-s-p-a-t-c-h-e-d/index.html @@ -1,63 +1 @@ - - - - - UNDISPATCHED - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

UNDISPATCHED

-
-
-

Immediately executes the coroutine until its first suspension point in the current thread similarly to the coroutine being started using Dispatchers.Unconfined. However, when the coroutine is resumed from suspension it is dispatched according to the CoroutineDispatcher in its context.

This is similar to ATOMIC in the sense that coroutine starts executing even if it was already cancelled, but the difference is that it starts executing in the same thread.

Cancellability of coroutine at suspension points depends on the particular implementation details of suspending functions as in DEFAULT.

Unconfined event loop

Unlike Dispatchers.Unconfined and MainCoroutineDispatcher.immediate, nested undispatched coroutines do not form an event loop that otherwise prevents potential stack overflow in case of unlimited nesting.

-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-start/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-start/index.html index 6df38f172f..2f8366d2f4 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-start/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-start/index.html @@ -1,147 +1 @@ - - - - - CoroutineStart - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CoroutineStart

-
-
-
enum CoroutineStart : Enum<CoroutineStart>

Defines start options for coroutines builders. It is used in start parameter of launch, async, and other coroutine builder functions.

The summary of coroutine start options is:

  • DEFAULT -- immediately schedules coroutine for execution according to its context;

  • LAZY -- starts coroutine lazily, only when it is needed;

  • ATOMIC -- atomically (in a non-cancellable way) schedules coroutine for execution according to its context;

  • UNDISPATCHED -- immediately executes coroutine until its first suspension point in the current thread.

-
-
-
-
-

Entries

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Immediately executes the coroutine until its first suspension point in the current thread similarly to the coroutine being started using Dispatchers.Unconfined. However, when the coroutine is resumed from suspension it is dispatched according to the CoroutineDispatcher in its context.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Atomically (i.e., in a non-cancellable way) schedules the coroutine for execution according to its context. This is similar to DEFAULT, but the coroutine cannot be cancelled before it starts executing.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Starts the coroutine lazily, only when it is needed.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Default -- immediately schedules the coroutine for execution according to its context.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-d-e-b-u-g_-p-r-o-p-e-r-t-y_-n-a-m-e.html b/kotlinx-coroutines-core/kotlinx.coroutines/-d-e-b-u-g_-p-r-o-p-e-r-t-y_-n-a-m-e.html index f22210cec4..cea8954c5c 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-d-e-b-u-g_-p-r-o-p-e-r-t-y_-n-a-m-e.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-d-e-b-u-g_-p-r-o-p-e-r-t-y_-n-a-m-e.html @@ -1,72 +1 @@ - - - - - DEBUG_PROPERTY_NAME - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

DEBUG_PROPERTY_NAME

-
-
-
-
const val DEBUG_PROPERTY_NAME: String

Name of the property that controls coroutine debugging.

Debugging facilities

In debug mode every coroutine is assigned a unique consecutive identifier. Every thread that executes a coroutine has its name modified to include the name and identifier of the currently running coroutine.

Enable debugging facilities with "kotlinx.coroutines.debug" (DEBUG_PROPERTY_NAME) system property, use the following values:

Coroutine name can be explicitly assigned using CoroutineName context element. The string "coroutine" is used as a default name.

Debugging facilities are implemented by newCoroutineContext function that is used in all coroutine builders to create context of a new coroutine.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-d-e-b-u-g_-p-r-o-p-e-r-t-y_-v-a-l-u-e_-a-u-t-o.html b/kotlinx-coroutines-core/kotlinx.coroutines/-d-e-b-u-g_-p-r-o-p-e-r-t-y_-v-a-l-u-e_-a-u-t-o.html index 554adc25e4..002b44e7d4 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-d-e-b-u-g_-p-r-o-p-e-r-t-y_-v-a-l-u-e_-a-u-t-o.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-d-e-b-u-g_-p-r-o-p-e-r-t-y_-v-a-l-u-e_-a-u-t-o.html @@ -1,72 +1 @@ - - - - - DEBUG_PROPERTY_VALUE_AUTO - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

DEBUG_PROPERTY_VALUE_AUTO

-
-
-
-
const val DEBUG_PROPERTY_VALUE_AUTO: String

Automatic debug configuration value for DEBUG_PROPERTY_NAME.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-d-e-b-u-g_-p-r-o-p-e-r-t-y_-v-a-l-u-e_-o-f-f.html b/kotlinx-coroutines-core/kotlinx.coroutines/-d-e-b-u-g_-p-r-o-p-e-r-t-y_-v-a-l-u-e_-o-f-f.html index 695143841e..50d02071b2 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-d-e-b-u-g_-p-r-o-p-e-r-t-y_-v-a-l-u-e_-o-f-f.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-d-e-b-u-g_-p-r-o-p-e-r-t-y_-v-a-l-u-e_-o-f-f.html @@ -1,72 +1 @@ - - - - - DEBUG_PROPERTY_VALUE_OFF - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

DEBUG_PROPERTY_VALUE_OFF

-
-
-
-
const val DEBUG_PROPERTY_VALUE_OFF: String

Debug turned on value for DEBUG_PROPERTY_NAME.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-d-e-b-u-g_-p-r-o-p-e-r-t-y_-v-a-l-u-e_-o-n.html b/kotlinx-coroutines-core/kotlinx.coroutines/-d-e-b-u-g_-p-r-o-p-e-r-t-y_-v-a-l-u-e_-o-n.html index 82f43f7775..8b2d274342 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-d-e-b-u-g_-p-r-o-p-e-r-t-y_-v-a-l-u-e_-o-n.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-d-e-b-u-g_-p-r-o-p-e-r-t-y_-v-a-l-u-e_-o-n.html @@ -1,72 +1 @@ - - - - - DEBUG_PROPERTY_VALUE_ON - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

DEBUG_PROPERTY_VALUE_ON

-
-
-
-
const val DEBUG_PROPERTY_VALUE_ON: String

Debug turned on value for DEBUG_PROPERTY_NAME.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/await.html b/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/await.html index d31d051396..47c8bb6c96 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/await.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/await.html @@ -1,72 +1 @@ - - - - - await - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

await

-
-
-
-
abstract suspend fun await(): T

Awaits for completion of this value without blocking a thread and resumes when deferred computation is complete, returning the resulting value or throwing the corresponding exception if the deferred was cancelled.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this suspending function is waiting, this function immediately resumes with CancellationException. There is a prompt cancellation guarantee. If the job was cancelled while this function was suspended, it will not resume successfully. See suspendCancellableCoroutine documentation for low-level details.

This function can be used in select invocation with onAwait clause. Use isCompleted to check for completion of this deferred value without waiting.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/get-completed.html b/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/get-completed.html index 86beb7cffc..1882f9c20f 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/get-completed.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/get-completed.html @@ -1,72 +1 @@ - - - - - getCompleted - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

getCompleted

-
-
-
-
abstract fun getCompleted(): T

Returns completed result or throws IllegalStateException if this deferred value has not completed yet. It throws the corresponding exception if this deferred was cancelled.

This function is designed to be used from invokeOnCompletion handlers, when there is an absolute certainty that the value is already complete. See also getCompletionExceptionOrNull.

Note: This is an experimental api. This function may be removed or renamed in the future.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/get-completion-exception-or-null.html b/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/get-completion-exception-or-null.html index 4fbbd5a8b4..98c31e4b70 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/get-completion-exception-or-null.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/get-completion-exception-or-null.html @@ -1,72 +1 @@ - - - - - getCompletionExceptionOrNull - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

getCompletionExceptionOrNull

-
-
-
-
abstract fun getCompletionExceptionOrNull(): Throwable?

Returns completion exception result if this deferred was cancelled and has completed, null if it had completed normally, or throws IllegalStateException if this deferred value has not completed yet.

This function is designed to be used from invokeOnCompletion handlers, when there is an absolute certainty that the value is already complete. See also getCompleted.

Note: This is an experimental api. This function may be removed or renamed in the future.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/index.html index e4ef1287dc..c8da021893 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/index.html @@ -1,182 +1 @@ - - - - - Deferred - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Deferred

-
-
-
interface Deferred<out T> : Job

Deferred value is a non-blocking cancellable future — it is a Job with a result.

It is created with the async coroutine builder or via the constructor of CompletableDeferred class. It is in active state while the value is being computed.

Deferred has the same state machine as the Job with additional convenience methods to retrieve the successful or failed result of the computation that was carried out. The result of the deferred is available when it is completed and can be retrieved by await method, which throws an exception if the deferred had failed. Note that a cancelled deferred is also considered as completed. The corresponding exception can be retrieved via getCompletionExceptionOrNull from a completed instance of deferred.

Usually, a deferred value is created in active state (it is created and started). However, the async coroutine builder has an optional start parameter that creates a deferred value in new state when this parameter is set to CoroutineStart.LAZY. Such a deferred can be be made active by invoking start, join, or await.

A deferred value is a Job. A job in the coroutineContext of async builder represents the coroutine itself.

All functions on this interface and on all interfaces derived from it are thread-safe and can be safely invoked from concurrent coroutines without external synchronization.

Deferred interface and all its derived interfaces are not stable for inheritance in 3rd party libraries, as new methods might be added to this interface in the future, but is stable for use.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract suspend fun await(): T

Awaits for completion of this value without blocking a thread and resumes when deferred computation is complete, returning the resulting value or throwing the corresponding exception if the deferred was cancelled.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun getCompleted(): T

Returns completed result or throws IllegalStateException if this deferred value has not completed yet. It throws the corresponding exception if this deferred was cancelled.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun getCompletionExceptionOrNull(): Throwable?

Returns completion exception result if this deferred was cancelled and has completed, null if it had completed normally, or throws IllegalStateException if this deferred value has not completed yet.

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val onAwait: SelectClause1<T>

Clause for select expression of await suspending function that selects with the deferred value when it is resolved. The select invocation fails if the deferred value completes exceptionally (either fails or it cancelled).

-
-
-
-
-
-

Inheritors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Extensions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Deferred<T>.asPromise(): Promise<T>

Converts this deferred value to the instance of Promise.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/on-await.html b/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/on-await.html index 2f649e8cd5..4dfa8f251b 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/on-await.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/on-await.html @@ -1,72 +1 @@ - - - - - onAwait - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

onAwait

-
-
-
-
abstract val onAwait: SelectClause1<T>

Clause for select expression of await suspending function that selects with the deferred value when it is resolved. The select invocation fails if the deferred value completes exceptionally (either fails or it cancelled).

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-delicate-coroutines-api/-delicate-coroutines-api.html b/kotlinx-coroutines-core/kotlinx.coroutines/-delicate-coroutines-api/-delicate-coroutines-api.html index 72a60c64ba..1e29396045 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-delicate-coroutines-api/-delicate-coroutines-api.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-delicate-coroutines-api/-delicate-coroutines-api.html @@ -1,72 +1 @@ - - - - - DelicateCoroutinesApi - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

DelicateCoroutinesApi

-
-
-
-
fun DelicateCoroutinesApi()
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-delicate-coroutines-api/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-delicate-coroutines-api/index.html index fd6bcb863a..7823aa3651 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-delicate-coroutines-api/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-delicate-coroutines-api/index.html @@ -1,96 +1 @@ - - - - - DelicateCoroutinesApi - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

DelicateCoroutinesApi

-
-
-
annotation class DelicateCoroutinesApi

Marks declarations in the coroutines that are delicate — they have limited use-case and shall be used with care in general code. Any use of a delicate declaration has to be carefully reviewed to make sure it is properly used and does not create problems like memory and resource leaks. Carefully read documentation of any declaration marked as DelicateCoroutinesApi.

-
-
-
-
-

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun DelicateCoroutinesApi()
-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-default.html b/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-default.html index e14fe102f2..9d94eec130 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-default.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-default.html @@ -1,108 +1 @@ - - - - - Default - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Default

-
-
-
-
expect val Default: CoroutineDispatcher

The default CoroutineDispatcher that is used by all standard builders like launch, async, etc if neither a dispatcher nor any other ContinuationInterceptor is specified in their context.

It is backed by a shared pool of threads on JVM. By default, the maximum number of threads used by this dispatcher is equal to the number of CPU cores, but is at least two.

actual val Default: CoroutineDispatcher
actual val Default: CoroutineDispatcher

The default CoroutineDispatcher that is used by all standard builders like launch, async, etc. if no dispatcher nor any other ContinuationInterceptor is specified in their context.

It is backed by a shared pool of threads on JVM. By default, the maximal level of parallelism used by this dispatcher is equal to the number of CPU cores, but is at least two. Level of parallelism X guarantees that no more than X tasks can be executed in this dispatcher in parallel.

actual val Default: CoroutineDispatcher
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-i-o.html b/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-i-o.html index 4142ca6da1..ca06b5f09d 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-i-o.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-i-o.html @@ -1,72 +1 @@ - - - - - IO - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

IO

-
-
-
-
val IO: CoroutineDispatcher

The CoroutineDispatcher that is designed for offloading blocking IO tasks to a shared pool of threads.

Additional threads in this pool are created and are shutdown on demand. The number of threads used by tasks in this dispatcher is limited by the value of "kotlinx.coroutines.io.parallelism" (IO_PARALLELISM_PROPERTY_NAME) system property. It defaults to the limit of 64 threads or the number of cores (whichever is larger).

Elasticity for limited parallelism

Dispatchers.IO has a unique property of elasticity: its views obtained with CoroutineDispatcher.limitedParallelism are not restricted by the Dispatchers.IO parallelism. Conceptually, there is a dispatcher backed by an unlimited pool of threads, and both Dispatchers.IO and views of Dispatchers.IO are actually views of that dispatcher. In practice this means that, despite not abiding by Dispatchers.IO's parallelism restrictions, its views share threads and resources with it.

In the following example

// 100 threads for MySQL connection
val myMysqlDbDispatcher = Dispatchers.IO.limitedParallelism(100)
// 60 threads for MongoDB connection
val myMongoDbDispatcher = Dispatchers.IO.limitedParallelism(60)

the system may have up to 64 + 100 + 60 threads dedicated to blocking tasks during peak loads, but during its steady state there is only a small number of threads shared among Dispatchers.IO, myMysqlDbDispatcher and myMongoDbDispatcher.

Implementation note

This dispatcher and its views share threads with the Default dispatcher, so using withContext(Dispatchers.IO) { ... } when already running on the Default dispatcher typically does not lead to an actual switching to another thread. In such scenarios, the underlying implementation attempts to keep the execution on the same thread on a best-effort basis.

As a result of thread sharing, more than 64 (default parallelism) threads can be created (but not used) during operations over IO dispatcher.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-main.html b/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-main.html index ffc384a2e5..00e6db883c 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-main.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-main.html @@ -1,108 +1 @@ - - - - - Main - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Main

-
-
-
-
expect val Main: MainCoroutineDispatcher

A coroutine dispatcher that is confined to the Main thread operating with UI objects. Usually such dispatchers are single-threaded.

Access to this property may throw an IllegalStateException if no main dispatchers are present in the classpath.

Depending on platform and classpath, it can be mapped to different dispatchers:

  • On JS and Native it is equivalent to the Default dispatcher.

  • On JVM it is either the Android main thread dispatcher, JavaFx or Swing EDT dispatcher. It is chosen by the ServiceLoader.

In order to work with the Main dispatcher, the following artifact should be added to the project runtime dependencies:

  • kotlinx-coroutines-android — for Android Main thread dispatcher

  • kotlinx-coroutines-javafx — for JavaFx Application thread dispatcher

  • kotlinx-coroutines-swing — for Swing EDT dispatcher

Implementation note: MainCoroutineDispatcher.immediate is not supported on the Native and JS platforms.

actual val Main: MainCoroutineDispatcher
actual val Main: MainCoroutineDispatcher

A coroutine dispatcher that is confined to the Main thread operating with UI objects. This dispatcher can be used either directly or via MainScope factory. Usually such dispatcher is single-threaded.

Access to this property may throw IllegalStateException if no main thread dispatchers are present in the classpath.

Depending on platform and classpath it can be mapped to different dispatchers:

  • On JS and Native it is equivalent of Default dispatcher.

  • On JVM it is either Android main thread dispatcher, JavaFx or Swing EDT dispatcher. It is chosen by ServiceLoader.

In order to work with Main dispatcher, the following artifacts should be added to project runtime dependencies:

  • kotlinx-coroutines-android for Android Main thread dispatcher

  • kotlinx-coroutines-javafx for JavaFx Application thread dispatcher

  • kotlinx-coroutines-swing for Swing EDT dispatcher

In order to set a custom Main dispatcher for testing purposes, add the kotlinx-coroutines-test artifact to project test dependencies.

Implementation note: MainCoroutineDispatcher.immediate is not supported on Native and JS platforms.

actual val Main: MainCoroutineDispatcher
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-unconfined.html b/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-unconfined.html index 26027b67ff..938d3a7056 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-unconfined.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-unconfined.html @@ -1,108 +1 @@ - - - - - Unconfined - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Unconfined

-
-
-
-
expect val Unconfined: CoroutineDispatcher

A coroutine dispatcher that is not confined to any specific thread. It executes the initial continuation of a coroutine in the current call-frame and lets the coroutine resume in whatever thread that is used by the corresponding suspending function, without mandating any specific threading policy. Nested coroutines launched in this dispatcher form an event-loop to avoid stack overflows.

Event loop

Event loop semantics is a purely internal concept and has no guarantees on the order of execution except that all queued coroutines will be executed on the current thread in the lexical scope of the outermost unconfined coroutine.

For example, the following code:

withContext(Dispatchers.Unconfined) {
println(1)
withContext(Dispatchers.Unconfined) { // Nested unconfined
println(2)
}
println(3)
}
println("Done")

Can print both "1 2 3" and "1 3 2". This is an implementation detail that can be changed. However, it is guaranteed that "Done" will be printed only when both withContext calls are completed.

If you need your coroutine to be confined to a particular thread or a thread-pool after resumption, but still want to execute it in the current call-frame until its first suspension, you can use an optional CoroutineStart parameter in coroutine builders like launch and async setting it to the value of CoroutineStart.UNDISPATCHED.

actual val Unconfined: CoroutineDispatcher
actual val Unconfined: CoroutineDispatcher

A coroutine dispatcher that is not confined to any specific thread. It executes initial continuation of the coroutine in the current call-frame and lets the coroutine resume in whatever thread that is used by the corresponding suspending function, without mandating any specific threading policy. Nested coroutines launched in this dispatcher form an event-loop to avoid stack overflows.

Event loop

Event loop semantics is a purely internal concept and have no guarantees on the order of execution except that all queued coroutines will be executed on the current thread in the lexical scope of the outermost unconfined coroutine.

For example, the following code:

withContext(Dispatchers.Unconfined) {
println(1)
withContext(Dispatchers.Unconfined) { // Nested unconfined
println(2)
}
println(3)
}
println("Done")

Can print both "1 2 3" and "1 3 2", this is an implementation detail that can be changed. But it is guaranteed that "Done" will be printed only when both withContext are completed.

Note that if you need your coroutine to be confined to a particular thread or a thread-pool after resumption, but still want to execute it in the current call-frame until its first suspension, then you can use an optional CoroutineStart parameter in coroutine builders like launch and async setting it to the value of CoroutineStart.UNDISPATCHED.

actual val Unconfined: CoroutineDispatcher
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/index.html index 3af4cbf013..bef64e3c39 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/index.html @@ -1,202 +1 @@ - - - - - Dispatchers - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Dispatchers

-
-
-
expect object Dispatchers

Groups various implementations of CoroutineDispatcher.

actual object Dispatchers
actual object Dispatchers

Groups various implementations of CoroutineDispatcher.

actual object Dispatchers
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun shutdown()

Shuts down built-in dispatchers, such as Default and IO, stopping all the threads associated with them and making them reject all new tasks. Dispatcher used as a fallback for time-related operations (delay, withTimeout) and to handle rejected tasks from other dispatchers is also shut down.

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
expect val Default: CoroutineDispatcher

The default CoroutineDispatcher that is used by all standard builders like launch, async, etc if neither a dispatcher nor any other ContinuationInterceptor is specified in their context.

actual val Default: CoroutineDispatcher
actual val Default: CoroutineDispatcher

The default CoroutineDispatcher that is used by all standard builders like launch, async, etc. if no dispatcher nor any other ContinuationInterceptor is specified in their context.

actual val Default: CoroutineDispatcher
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
val IO: CoroutineDispatcher

The CoroutineDispatcher that is designed for offloading blocking IO tasks to a shared pool of threads.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
expect val Main: MainCoroutineDispatcher

A coroutine dispatcher that is confined to the Main thread operating with UI objects. Usually such dispatchers are single-threaded.

actual val Main: MainCoroutineDispatcher
actual val Main: MainCoroutineDispatcher

A coroutine dispatcher that is confined to the Main thread operating with UI objects. This dispatcher can be used either directly or via MainScope factory. Usually such dispatcher is single-threaded.

actual val Main: MainCoroutineDispatcher
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
expect val Unconfined: CoroutineDispatcher

A coroutine dispatcher that is not confined to any specific thread. It executes the initial continuation of a coroutine in the current call-frame and lets the coroutine resume in whatever thread that is used by the corresponding suspending function, without mandating any specific threading policy. Nested coroutines launched in this dispatcher form an event-loop to avoid stack overflows.

actual val Unconfined: CoroutineDispatcher
actual val Unconfined: CoroutineDispatcher

A coroutine dispatcher that is not confined to any specific thread. It executes initial continuation of the coroutine in the current call-frame and lets the coroutine resume in whatever thread that is used by the corresponding suspending function, without mandating any specific threading policy. Nested coroutines launched in this dispatcher form an event-loop to avoid stack overflows.

actual val Unconfined: CoroutineDispatcher
-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/shutdown.html b/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/shutdown.html index 20475951e1..80e6d04961 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/shutdown.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/shutdown.html @@ -1,72 +1 @@ - - - - - shutdown - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

shutdown

-
-
-
-
fun shutdown()

Shuts down built-in dispatchers, such as Default and IO, stopping all the threads associated with them and making them reject all new tasks. Dispatcher used as a fallback for time-related operations (delay, withTimeout) and to handle rejected tasks from other dispatchers is also shut down.

This is a delicate API. It is not supposed to be called from a general application-level code and its invocation is irreversible. The invocation of shutdown affects most of the coroutines machinery and leaves the coroutines framework in an inoperable state. The shutdown method should only be invoked when there are no pending tasks or active coroutines. Otherwise, the behavior is unspecified: the call to shutdown may throw an exception without completing the shutdown, or it may finish successfully, but the remaining jobs will be in a permanent dormant state, never completing nor executing.

The main goal of the shutdown is to stop all background threads associated with the coroutines framework in order to make kotlinx.coroutines classes unloadable by Java Virtual Machine. It is only recommended to be used in containerized environments (OSGi, Gradle plugins system, IDEA plugins) at the end of the container lifecycle.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-disposable-handle/dispose.html b/kotlinx-coroutines-core/kotlinx.coroutines/-disposable-handle/dispose.html index 90fa9f965d..8b07da1042 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-disposable-handle/dispose.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-disposable-handle/dispose.html @@ -1,72 +1 @@ - - - - - dispose - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

dispose

-
-
-
-
abstract fun dispose()

Disposes the corresponding object, making it eligible for garbage collection. Repeated invocation of this function has no effect.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-disposable-handle/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-disposable-handle/index.html index 297e93baae..e5c4ae4b21 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-disposable-handle/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-disposable-handle/index.html @@ -1,96 +1 @@ - - - - - DisposableHandle - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

DisposableHandle

-
-
-
fun interface DisposableHandle

A handle to an allocated object that can be disposed to make it eligible for garbage collection.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun dispose()

Disposes the corresponding object, making it eligible for garbage collection. Repeated invocation of this function has no effect.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-executor-coroutine-dispatcher/-executor-coroutine-dispatcher.html b/kotlinx-coroutines-core/kotlinx.coroutines/-executor-coroutine-dispatcher/-executor-coroutine-dispatcher.html index 4de52a805c..d9a526893d 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-executor-coroutine-dispatcher/-executor-coroutine-dispatcher.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-executor-coroutine-dispatcher/-executor-coroutine-dispatcher.html @@ -1,72 +1 @@ - - - - - ExecutorCoroutineDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

ExecutorCoroutineDispatcher

-
-
-
-
fun ExecutorCoroutineDispatcher()
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-executor-coroutine-dispatcher/close.html b/kotlinx-coroutines-core/kotlinx.coroutines/-executor-coroutine-dispatcher/close.html index fca39120f4..44bbbef660 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-executor-coroutine-dispatcher/close.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-executor-coroutine-dispatcher/close.html @@ -1,72 +1 @@ - - - - - close - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

close

-
-
-
-
abstract override fun close()

Closes this coroutine dispatcher and shuts down its executor.

It may throw an exception if this dispatcher is global and cannot be closed.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-executor-coroutine-dispatcher/executor.html b/kotlinx-coroutines-core/kotlinx.coroutines/-executor-coroutine-dispatcher/executor.html index d846c71020..51ee1f11db 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-executor-coroutine-dispatcher/executor.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-executor-coroutine-dispatcher/executor.html @@ -1,72 +1 @@ - - - - - executor - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

executor

-
-
-
-
abstract val executor: Executor

Underlying executor of current CoroutineDispatcher.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-executor-coroutine-dispatcher/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-executor-coroutine-dispatcher/index.html index 8f5de67a1c..c7079b429a 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-executor-coroutine-dispatcher/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-executor-coroutine-dispatcher/index.html @@ -1,134 +1 @@ - - - - - ExecutorCoroutineDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

ExecutorCoroutineDispatcher

-
-
-
abstract class ExecutorCoroutineDispatcher : CoroutineDispatcher, Closeable

CoroutineDispatcher that has underlying Executor for dispatching tasks. Instances of ExecutorCoroutineDispatcher should be closed by the owner of the dispatcher.

This class is generally used as a bridge between coroutine-based API and asynchronous API that requires an instance of the Executor.

-
-
-
-
-

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun ExecutorCoroutineDispatcher()
-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract override fun close()

Closes this coroutine dispatcher and shuts down its executor.

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val executor: Executor

Underlying executor of current CoroutineDispatcher.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-experimental-coroutines-api/-experimental-coroutines-api.html b/kotlinx-coroutines-core/kotlinx.coroutines/-experimental-coroutines-api/-experimental-coroutines-api.html index 225acc42da..f4f65bc98c 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-experimental-coroutines-api/-experimental-coroutines-api.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-experimental-coroutines-api/-experimental-coroutines-api.html @@ -1,72 +1 @@ - - - - - ExperimentalCoroutinesApi - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

ExperimentalCoroutinesApi

-
-
-
-
fun ExperimentalCoroutinesApi()
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-experimental-coroutines-api/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-experimental-coroutines-api/index.html index 4d84bb6a27..aee22a4eff 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-experimental-coroutines-api/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-experimental-coroutines-api/index.html @@ -1,96 +1 @@ - - - - - ExperimentalCoroutinesApi - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

ExperimentalCoroutinesApi

-
-
-

Marks declarations that are still experimental in coroutines API, which means that the design of the corresponding declarations has open issues which may (or may not) lead to their changes in the future. Roughly speaking, there is a chance that those declarations will be deprecated in the near future or the semantics of their behavior may change in some way that may break some code.

-
-
-
-
-

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun ExperimentalCoroutinesApi()
-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-flow-preview/-flow-preview.html b/kotlinx-coroutines-core/kotlinx.coroutines/-flow-preview/-flow-preview.html index d92bebada3..11adb60785 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-flow-preview/-flow-preview.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-flow-preview/-flow-preview.html @@ -1,72 +1 @@ - - - - - FlowPreview - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

FlowPreview

-
-
-
-
fun FlowPreview()
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-flow-preview/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-flow-preview/index.html index c3a7ca8315..96d4383b40 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-flow-preview/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-flow-preview/index.html @@ -1,96 +1 @@ - - - - - FlowPreview - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

FlowPreview

-
-
-

Marks Flow-related API as a feature preview.

Flow preview has no backward compatibility guarantees, including both binary and source compatibility. Its API and semantics can and will be changed in next releases.

Feature preview can be used to evaluate its real-world strengths and weaknesses, gather and provide feedback. According to the feedback, Flow will be refined on its road to stabilization and promotion to a stable API.

The best way to speed up preview feature promotion is providing the feedback on the feature.

-
-
-
-
-

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun FlowPreview()
-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-global-scope/coroutine-context.html b/kotlinx-coroutines-core/kotlinx.coroutines/-global-scope/coroutine-context.html index 01b1eb205a..1f0a277ca6 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-global-scope/coroutine-context.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-global-scope/coroutine-context.html @@ -1,72 +1 @@ - - - - - coroutineContext - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

coroutineContext

-
-
-
-
open override val coroutineContext: CoroutineContext

Returns EmptyCoroutineContext.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-global-scope/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-global-scope/index.html index 0b4de2b88d..074b7afb25 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-global-scope/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-global-scope/index.html @@ -1,96 +1 @@ - - - - - GlobalScope - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

GlobalScope

-
-
-
object GlobalScope : CoroutineScope

A global CoroutineScope not bound to any job. Global scope is used to launch top-level coroutines which are operating on the whole application lifetime and are not cancelled prematurely.

Active coroutines launched in GlobalScope do not keep the process alive. They are like daemon threads.

This is a delicate API. It is easy to accidentally create resource or memory leaks when GlobalScope is used. A coroutine launched in GlobalScope is not subject to the principle of structured concurrency, so if it hangs or gets delayed due to a problem (e.g. due to a slow network), it will stay working and consuming resources. For example, consider the following code:

fun loadConfiguration() {
GlobalScope.launch {
val config = fetchConfigFromServer() // network request
updateConfiguration(config)
}
}

A call to loadConfiguration creates a coroutine in the GlobalScope that works in background without any provision to cancel it or to wait for its completion. If a network is slow, it keeps waiting in background, consuming resources. Repeated calls to loadConfiguration will consume more and more resources.

Possible replacements

In many cases uses of GlobalScope should be removed, marking the containing operation with suspend, for example:

suspend fun loadConfiguration() {
val config = fetchConfigFromServer() // network request
updateConfiguration(config)
}

In cases when GlobalScope.launch was used to launch multiple concurrent operations, the corresponding operations shall be grouped with coroutineScope instead:

// concurrently load configuration and data
suspend fun loadConfigurationAndData() {
coroutineScope {
launch { loadConfiguration() }
launch { loadData() }
}
}

In top-level code, when launching a concurrent operation from a non-suspending context, an appropriately confined instance of CoroutineScope shall be used instead of a GlobalScope. See docs on CoroutineScope for details.

GlobalScope vs custom scope

Do not replace GlobalScope.launch { ... } with CoroutineScope().launch { ... } constructor function call. The latter has the same pitfalls as GlobalScope. See CoroutineScope documentation on the intended usage of CoroutineScope() constructor function.

Legitimate use-cases

There are limited circumstances under which GlobalScope can be legitimately and safely used, such as top-level background processes that must stay active for the whole duration of the application's lifetime. Because of that, any use of GlobalScope requires an explicit opt-in with @OptIn(DelicateCoroutinesApi::class), like this:

// A global coroutine to log statistics every second, must be always active
@OptIn(DelicateCoroutinesApi::class)
val globalScopeReporter = GlobalScope.launch {
while (true) {
delay(1000)
logStatistics()
}
}
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
open override val coroutineContext: CoroutineContext
-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-i-o_-p-a-r-a-l-l-e-l-i-s-m_-p-r-o-p-e-r-t-y_-n-a-m-e.html b/kotlinx-coroutines-core/kotlinx.coroutines/-i-o_-p-a-r-a-l-l-e-l-i-s-m_-p-r-o-p-e-r-t-y_-n-a-m-e.html index 9a91414cd2..5a709c8a49 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-i-o_-p-a-r-a-l-l-e-l-i-s-m_-p-r-o-p-e-r-t-y_-n-a-m-e.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-i-o_-p-a-r-a-l-l-e-l-i-s-m_-p-r-o-p-e-r-t-y_-n-a-m-e.html @@ -1,72 +1 @@ - - - - - IO_PARALLELISM_PROPERTY_NAME - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

IO_PARALLELISM_PROPERTY_NAME

-
-
-
-
const val IO_PARALLELISM_PROPERTY_NAME: String

Name of the property that defines the maximal number of threads that are used by Dispatchers.IO coroutines dispatcher.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-internal-coroutines-api/-internal-coroutines-api.html b/kotlinx-coroutines-core/kotlinx.coroutines/-internal-coroutines-api/-internal-coroutines-api.html index eabcde5eaf..9f6ed977d0 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-internal-coroutines-api/-internal-coroutines-api.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-internal-coroutines-api/-internal-coroutines-api.html @@ -1,72 +1 @@ - - - - - InternalCoroutinesApi - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

InternalCoroutinesApi

-
-
-
-
fun InternalCoroutinesApi()
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-internal-coroutines-api/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-internal-coroutines-api/index.html index 9c392e4402..694a75d7aa 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-internal-coroutines-api/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-internal-coroutines-api/index.html @@ -1,96 +1 @@ - - - - - InternalCoroutinesApi - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

InternalCoroutinesApi

-
-
-

Marks declarations that are internal in coroutines API, which means that should not be used outside of kotlinx.coroutines, because their signatures and semantics will change between future releases without any warnings and without providing any migration aids.

-
-
-
-
-

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun InternalCoroutinesApi()
-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-job.html b/kotlinx-coroutines-core/kotlinx.coroutines/-job.html index 8cfaf03544..b1995b6087 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-job.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-job.html @@ -1,72 +1 @@ - - - - - Job - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Job

-
-
-
-
fun Job(parent: Job? = null): CompletableJob

Creates a job object in an active state. A failure of any child of this job immediately causes this job to fail, too, and cancels the rest of its children.

To handle children failure independently of each other use SupervisorJob.

If parent job is specified, then this job becomes a child job of its parent and is cancelled when its parent fails or is cancelled. All this job's children are cancelled in this case, too. The invocation of cancel with exception (other than CancellationException) on this job also cancels parent.

Conceptually, the resulting job works in the same way as the job created by the launch { body } invocation (see launch), but without any code in the body. It is active until cancelled or completed. Invocation of CompletableJob.complete or CompletableJob.completeExceptionally corresponds to the successful or failed completion of the body of the coroutine.

Parameters

parent

an optional parent job.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-job/-key/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-job/-key/index.html index 3264c179f7..2c77d0c534 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-job/-key/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-job/-key/index.html @@ -1,77 +1 @@ - - - - - Key - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Key

-
-
-
object Key : CoroutineContext.Key<Job>

Key for Job instance in the coroutine context.

-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-job/cancel.html b/kotlinx-coroutines-core/kotlinx.coroutines/-job/cancel.html index 16c244569d..323db2a440 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-job/cancel.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-job/cancel.html @@ -1,72 +1 @@ - - - - - cancel - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

cancel

-
-
-
-
abstract fun cancel(cause: CancellationException? = null)

Cancels this job with an optional cancellation cause. A cause can be used to specify an error message or to provide other details on the cancellation reason for debugging purposes. See Job documentation for full explanation of cancellation machinery.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-job/children.html b/kotlinx-coroutines-core/kotlinx.coroutines/-job/children.html index f6c04db8e0..f0fd9ac336 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-job/children.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-job/children.html @@ -1,72 +1 @@ - - - - - children - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

children

-
-
-
-
abstract val children: Sequence<Job>

Returns a sequence of this job's children.

A job becomes a child of this job when it is constructed with this job in its CoroutineContext or using an explicit parent parameter.

A parent-child relation has the following effect:

  • Cancellation of parent with cancel or its exceptional completion (failure) immediately cancels all its children.

  • Parent cannot complete until all its children are complete. Parent waits for all its children to complete in completing or cancelling state.

  • Uncaught exception in a child, by default, cancels parent. This applies even to children created with async and other future-like coroutine builders, even though their exceptions are caught and are encapsulated in their result. This default behavior can be overridden with SupervisorJob.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-job/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-job/index.html index 0e459d9edb..5ebe7062ae 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-job/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-job/index.html @@ -1,358 +1 @@ - - - - - Job - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Job

-
-
-
interface Job : CoroutineContext.Element

A background job. Conceptually, a job is a cancellable thing with a life-cycle that culminates in its completion.

Jobs can be arranged into parent-child hierarchies where cancellation of a parent leads to immediate cancellation of all its children recursively. Failure of a child with an exception other than CancellationException immediately cancels its parent and, consequently, all its other children. This behavior can be customized using SupervisorJob.

The most basic instances of Job interface are created like this:

  • Coroutine job is created with launch coroutine builder. It runs a specified block of code and completes on completion of this block.

  • CompletableJob is created with a Job() factory function. It is completed by calling CompletableJob.complete.

Conceptually, an execution of a job does not produce a result value. Jobs are launched solely for their side-effects. See Deferred interface for a job that produces a result.

Job states

A job has the following states:

StateisActiveisCompletedisCancelled
New (optional initial state)falsefalsefalse
Active (default initial state)truefalsefalse
Completing (transient state)truefalsefalse
Cancelling (transient state)falsefalsetrue
Cancelled (final state)falsetruetrue
Completed (final state)falsetruefalse

Usually, a job is created in the active state (it is created and started). However, coroutine builders that provide an optional start parameter create a coroutine in the new state when this parameter is set to CoroutineStart.LAZY. Such a job can be made active by invoking start or join.

A job is active while the coroutine is working or until CompletableJob is completed, or until it fails or cancelled.

Failure of an active job with an exception makes it cancelling. A job can be cancelled at any time with cancel function that forces it to transition to the cancelling state immediately. The job becomes cancelled when it finishes executing its work and all its children complete.

Completion of an active coroutine's body or a call to CompletableJob.complete transitions the job to the completing state. It waits in the completing state for all its children to complete before transitioning to the completed state. Note that completing state is purely internal to the job. For an outside observer a completing job is still active, while internally it is waiting for its children.

                                          wait children
+-----+ start +--------+ complete +-------------+ finish +-----------+
| New | -----> | Active | ---------> | Completing | -------> | Completed |
+-----+ +--------+ +-------------+ +-----------+
| cancel / fail |
| +----------------+
| |
V V
+------------+ finish +-----------+
| Cancelling | --------------------------------> | Cancelled |
+------------+ +-----------+

A Job instance in the coroutineContext represents the coroutine itself.

Cancellation cause

A coroutine job is said to complete exceptionally when its body throws an exception; a CompletableJob is completed exceptionally by calling CompletableJob.completeExceptionally. An exceptionally completed job is cancelled and the corresponding exception becomes the cancellation cause of the job.

Normal cancellation of a job is distinguished from its failure by the type of this exception that caused its cancellation. A coroutine that threw CancellationException is considered to be cancelled normally. If a cancellation cause is a different exception type, then the job is considered to have failed. When a job has failed, then its parent gets cancelled with the exception of the same type, thus ensuring transparency in delegating parts of the job to its children.

Note, that cancel function on a job only accepts CancellationException as a cancellation cause, thus calling cancel always results in a normal cancellation of a job, which does not lead to cancellation of its parent. This way, a parent can cancel its own children (cancelling all their children recursively, too) without cancelling itself.

Concurrency and synchronization

All functions on this interface and on all interfaces derived from it are thread-safe and can be safely invoked from concurrent coroutines without external synchronization.

Not stable for inheritance

Job interface and all its derived interfaces are not stable for inheritance in 3rd party libraries, as new methods might be added to this interface in the future, but is stable for use.

-
-
-
-
-

Types

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
object Key : CoroutineContext.Key<Job>

Key for Job instance in the coroutine context.

-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun cancel(cause: CancellationException? = null)

Cancels this job with an optional cancellation cause. A cause can be used to specify an error message or to provide other details on the cancellation reason for debugging purposes. See Job documentation for full explanation of cancellation machinery.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun invokeOnCompletion(handler: CompletionHandler): DisposableHandle

Registers handler that is synchronously invoked once on completion of this job. When the job is already complete, then the handler is immediately invoked with the job's exception or cancellation cause or null. Otherwise, the handler will be invoked once when this job is complete.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract suspend fun join()

Suspends the coroutine until this job is complete. This invocation resumes normally (without exception) when the job is complete for any reason and the Job of the invoking coroutine is still active. This function also starts the corresponding coroutine if the Job was still in new state.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun start(): Boolean

Starts coroutine related to this job (if any) if it was not started yet. The result is true if this invocation actually started coroutine or false if it was already started or completed.

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val children: Sequence<Job>

Returns a sequence of this job's children.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val isActive: Boolean

Returns true when this job is active -- it was already started and has not completed nor was cancelled yet. The job that is waiting for its children to complete is still considered to be active if it was not cancelled nor failed.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val isCancelled: Boolean

Returns true if this job was cancelled for any reason, either by explicit invocation of cancel or because it had failed or its child or parent was cancelled. In the general case, it does not imply that the job has already completed, because it may still be finishing whatever it was doing and waiting for its children to complete.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val isCompleted: Boolean

Returns true when this job has completed for any reason. A job that was cancelled or failed and has finished its execution is also considered complete. Job becomes complete only after all its children complete.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val onJoin: SelectClause0

Clause for select expression of join suspending function that selects when the job is complete. This clause never fails, even if the job completes exceptionally.

-
-
-
-
-
-

Inheritors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Extensions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun Job.cancel(message: String, cause: Throwable? = null)

Cancels current job, including all its children with a specified diagnostic error message. A cause can be specified to provide additional details on a cancellation reason for debugging purposes.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun Job.cancelAndJoin()

Cancels the job and suspends the invoking coroutine until the cancelled job is complete.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun Job.cancelChildren(cause: CancellationException? = null)

Cancels all children jobs of this coroutine using Job.cancel for all of them with an optional cancellation cause. Unlike Job.cancel on this job as a whole, the state of this job itself is not affected.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun Job.ensureActive()

Ensures that current job is active. If the job is no longer active, throws CancellationException. If the job was cancelled, thrown exception contains the original cancellation cause.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-job/invoke-on-completion.html b/kotlinx-coroutines-core/kotlinx.coroutines/-job/invoke-on-completion.html index 897bdfa01a..8c5e4d557e 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-job/invoke-on-completion.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-job/invoke-on-completion.html @@ -1,72 +1 @@ - - - - - invokeOnCompletion - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

invokeOnCompletion

-
-
-
-
abstract fun invokeOnCompletion(handler: CompletionHandler): DisposableHandle

Registers handler that is synchronously invoked once on completion of this job. When the job is already complete, then the handler is immediately invoked with the job's exception or cancellation cause or null. Otherwise, the handler will be invoked once when this job is complete.

The meaning of cause that is passed to the handler:

  • Cause is null when the job has completed normally.

  • Cause is an instance of CancellationException when the job was cancelled normally. It should not be treated as an error. In particular, it should not be reported to error logs.

  • Otherwise, the job had failed.

The resulting DisposableHandle can be used to dispose the registration of this handler and release its memory if its invocation is no longer needed. There is no need to dispose the handler after completion of this job. The references to all the handlers are released when this job completes.

Installed handler should not throw any exceptions. If it does, they will get caught, wrapped into CompletionHandlerException, and rethrown, potentially causing crash of unrelated code.

Note: Implementation of CompletionHandler must be fast, non-blocking, and thread-safe. This handler can be invoked concurrently with the surrounding code. There is no guarantee on the execution context in which the handler is invoked.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-job/is-active.html b/kotlinx-coroutines-core/kotlinx.coroutines/-job/is-active.html index 2eb3a5c257..f2cedad3c3 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-job/is-active.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-job/is-active.html @@ -1,72 +1 @@ - - - - - isActive - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

isActive

-
-
-
-
abstract val isActive: Boolean

Returns true when this job is active -- it was already started and has not completed nor was cancelled yet. The job that is waiting for its children to complete is still considered to be active if it was not cancelled nor failed.

See Job documentation for more details on job states.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-job/is-cancelled.html b/kotlinx-coroutines-core/kotlinx.coroutines/-job/is-cancelled.html index ef73541a56..fb28d1e410 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-job/is-cancelled.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-job/is-cancelled.html @@ -1,72 +1 @@ - - - - - isCancelled - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

isCancelled

-
-
-
-
abstract val isCancelled: Boolean

Returns true if this job was cancelled for any reason, either by explicit invocation of cancel or because it had failed or its child or parent was cancelled. In the general case, it does not imply that the job has already completed, because it may still be finishing whatever it was doing and waiting for its children to complete.

See Job documentation for more details on cancellation and failures.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-job/is-completed.html b/kotlinx-coroutines-core/kotlinx.coroutines/-job/is-completed.html index f72168f3c4..05fc46fc09 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-job/is-completed.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-job/is-completed.html @@ -1,72 +1 @@ - - - - - isCompleted - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

isCompleted

-
-
-
-
abstract val isCompleted: Boolean

Returns true when this job has completed for any reason. A job that was cancelled or failed and has finished its execution is also considered complete. Job becomes complete only after all its children complete.

See Job documentation for more details on job states.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-job/join.html b/kotlinx-coroutines-core/kotlinx.coroutines/-job/join.html index 4f212c5432..815d8d9820 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-job/join.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-job/join.html @@ -1,72 +1 @@ - - - - - join - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

join

-
-
-
-
abstract suspend fun join()

Suspends the coroutine until this job is complete. This invocation resumes normally (without exception) when the job is complete for any reason and the Job of the invoking coroutine is still active. This function also starts the corresponding coroutine if the Job was still in new state.

Note that the job becomes complete only when all its children are complete.

This suspending function is cancellable and always checks for a cancellation of the invoking coroutine's Job. If the Job of the invoking coroutine is cancelled or completed when this suspending function is invoked or while it is suspended, this function throws CancellationException.

In particular, it means that a parent coroutine invoking join on a child coroutine throws CancellationException if the child had failed, since a failure of a child coroutine cancels parent by default, unless the child was launched from within supervisorScope.

This function can be used in select invocation with onJoin clause. Use isCompleted to check for a completion of this job without waiting.

There is cancelAndJoin function that combines an invocation of cancel and join.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-job/on-join.html b/kotlinx-coroutines-core/kotlinx.coroutines/-job/on-join.html index 317fac8ee9..907f7c2ef4 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-job/on-join.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-job/on-join.html @@ -1,72 +1 @@ - - - - - onJoin - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

onJoin

-
-
-
-
abstract val onJoin: SelectClause0

Clause for select expression of join suspending function that selects when the job is complete. This clause never fails, even if the job completes exceptionally.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-job/start.html b/kotlinx-coroutines-core/kotlinx.coroutines/-job/start.html index 3cd7e310b4..0a9eed8b2a 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-job/start.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-job/start.html @@ -1,72 +1 @@ - - - - - start - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

start

-
-
-
-
abstract fun start(): Boolean

Starts coroutine related to this job (if any) if it was not started yet. The result is true if this invocation actually started coroutine or false if it was already started or completed.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-main-coroutine-dispatcher/-main-coroutine-dispatcher.html b/kotlinx-coroutines-core/kotlinx.coroutines/-main-coroutine-dispatcher/-main-coroutine-dispatcher.html index c0e634c110..bb7ddd1a6b 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-main-coroutine-dispatcher/-main-coroutine-dispatcher.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-main-coroutine-dispatcher/-main-coroutine-dispatcher.html @@ -1,72 +1 @@ - - - - - MainCoroutineDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

MainCoroutineDispatcher

-
-
-
-
fun MainCoroutineDispatcher()
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-main-coroutine-dispatcher/immediate.html b/kotlinx-coroutines-core/kotlinx.coroutines/-main-coroutine-dispatcher/immediate.html index 2da24bbe09..53d867d92f 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-main-coroutine-dispatcher/immediate.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-main-coroutine-dispatcher/immediate.html @@ -1,72 +1 @@ - - - - - immediate - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

immediate

-
-
-
-
abstract val immediate: MainCoroutineDispatcher

Returns dispatcher that executes coroutines immediately when it is already in the right context (e.g. current looper is the same as this handler's looper) without an additional re-dispatch.

Immediate dispatcher is safe from stack overflows and in case of nested invocations forms event-loop similar to Dispatchers.Unconfined. The event loop is an advanced topic and its implications can be found in Dispatchers.Unconfined documentation. The formed event-loop is shared with Unconfined and other immediate dispatchers, potentially overlapping tasks between them.

Example of usage:

suspend fun updateUiElement(val text: String) {
/*
* If it is known that updateUiElement can be invoked both from the Main thread and from other threads,
* `immediate` dispatcher is used as a performance optimization to avoid unnecessary dispatch.
*
* In that case, when `updateUiElement` is invoked from the Main thread, `uiElement.text` will be
* invoked immediately without any dispatching, otherwise, the `Dispatchers.Main` dispatch cycle will be triggered.
*/
withContext(Dispatchers.Main.immediate) {
uiElement.text = text
}
// Do context-independent logic such as logging
}

Method may throw UnsupportedOperationException if immediate dispatching is not supported by current dispatcher, please refer to specific dispatcher documentation.

Dispatchers.Main supports immediate execution for Android, JavaFx and Swing platforms.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-main-coroutine-dispatcher/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-main-coroutine-dispatcher/index.html index c01e430079..eda77874bd 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-main-coroutine-dispatcher/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-main-coroutine-dispatcher/index.html @@ -1,151 +1 @@ - - - - - MainCoroutineDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

MainCoroutineDispatcher

-
-
-
abstract class MainCoroutineDispatcher : CoroutineDispatcher

Base class for special CoroutineDispatcher which is confined to application "Main" or "UI" thread and used for any UI-based activities. Instance of MainDispatcher can be obtained by Dispatchers.Main.

Platform may or may not provide instance of MainDispatcher, see documentation to Dispatchers.Main

-
-
-
-
-

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun MainCoroutineDispatcher()
-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
open override fun limitedParallelism(parallelism: Int): CoroutineDispatcher

Creates a view of the current dispatcher that limits the parallelism to the given value. The resulting view uses the original dispatcher for execution, but with the guarantee that no more than parallelism coroutines are executed at the same time.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
open override fun toString(): String

Returns a name of this main dispatcher for debugging purposes. This implementation returns Dispatchers.Main or Dispatchers.Main.immediate if it is the same as the corresponding reference in Dispatchers or a short class-name representation with address otherwise.

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val immediate: MainCoroutineDispatcher

Returns dispatcher that executes coroutines immediately when it is already in the right context (e.g. current looper is the same as this handler's looper) without an additional re-dispatch.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-main-coroutine-dispatcher/limited-parallelism.html b/kotlinx-coroutines-core/kotlinx.coroutines/-main-coroutine-dispatcher/limited-parallelism.html index b4788d22b2..87cde0a549 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-main-coroutine-dispatcher/limited-parallelism.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-main-coroutine-dispatcher/limited-parallelism.html @@ -1,72 +1 @@ - - - - - limitedParallelism - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

limitedParallelism

-
-
-
-
open override fun limitedParallelism(parallelism: Int): CoroutineDispatcher

Creates a view of the current dispatcher that limits the parallelism to the given value. The resulting view uses the original dispatcher for execution, but with the guarantee that no more than parallelism coroutines are executed at the same time.

This method does not impose restrictions on the number of views or the total sum of parallelism values, each view controls its own parallelism independently with the guarantee that the effective parallelism of all views cannot exceed the actual parallelism of the original dispatcher.

Limitations

The default implementation of limitedParallelism does not support direct dispatchers, such as executing the given runnable in place during dispatch calls. Any dispatcher that may return false from isDispatchNeeded is considered direct. For direct dispatchers, it is recommended to override this method and provide a domain-specific implementation or to throw an UnsupportedOperationException.

Example of usage

private val backgroundDispatcher = newFixedThreadPoolContext(4, "App Background")
// At most 2 threads will be processing images as it is really slow and CPU-intensive
private val imageProcessingDispatcher = backgroundDispatcher.limitedParallelism(2)
// At most 3 threads will be processing JSON to avoid image processing starvation
private val jsonProcessingDispatcher = backgroundDispatcher.limitedParallelism(3)
// At most 1 thread will be doing IO
private val fileWriterDispatcher = backgroundDispatcher.limitedParallelism(1)

Note how in this example the application has an executor with 4 threads, but the total sum of all limits is 6. Still, at most 4 coroutines can be executed simultaneously as each view limits only its own parallelism.

Note that this example was structured in such a way that it illustrates the parallelism guarantees. In practice, it is usually better to use Dispatchers.IO or Dispatchers.Default instead of creating a backgroundDispatcher. It is both possible and advised to call limitedParallelism on them.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-main-coroutine-dispatcher/to-string.html b/kotlinx-coroutines-core/kotlinx.coroutines/-main-coroutine-dispatcher/to-string.html index 1568772fce..53112d3087 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-main-coroutine-dispatcher/to-string.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-main-coroutine-dispatcher/to-string.html @@ -1,72 +1 @@ - - - - - toString - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

toString

-
-
-
-
open override fun toString(): String

Returns a name of this main dispatcher for debugging purposes. This implementation returns Dispatchers.Main or Dispatchers.Main.immediate if it is the same as the corresponding reference in Dispatchers or a short class-name representation with address otherwise.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-main-scope.html b/kotlinx-coroutines-core/kotlinx.coroutines/-main-scope.html index 04ad22c694..06fc35298a 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-main-scope.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-main-scope.html @@ -1,72 +1 @@ - - - - - MainScope - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

MainScope

-
-
-
-
fun MainScope(): CoroutineScope

Creates the main CoroutineScope for UI components.

Example of use:

class MyAndroidActivity {
private val scope = MainScope()

override fun onDestroy() {
super.onDestroy()
scope.cancel()
}
}

The resulting scope has SupervisorJob and Dispatchers.Main context elements. If you want to append additional elements to the main scope, use CoroutineScope.plus operator: val scope = MainScope() + CoroutineName("MyActivity").

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-non-cancellable/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-non-cancellable/index.html index 0b63da03fb..3e18a5eb5a 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-non-cancellable/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-non-cancellable/index.html @@ -1,77 +1 @@ - - - - - NonCancellable - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

NonCancellable

-
-
-
object NonCancellable : AbstractCoroutineContextElement, Job

A non-cancelable job that is always active. It is designed for withContext function to prevent cancellation of code blocks that need to be executed without cancellation.

Use it like this:

withContext(NonCancellable) {
// this code will not be cancelled
}

WARNING: This object is not designed to be used with launch, async, and other coroutine builders. if you write launch(NonCancellable) { ... } then not only the newly launched job will not be cancelled when the parent is cancelled, the whole parent-child relation between parent and child is severed. The parent will not wait for the child's completion, nor will be cancelled when the child crashed.

-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-obsolete-coroutines-api/-obsolete-coroutines-api.html b/kotlinx-coroutines-core/kotlinx.coroutines/-obsolete-coroutines-api/-obsolete-coroutines-api.html index d6b4f7354b..a44add640e 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-obsolete-coroutines-api/-obsolete-coroutines-api.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-obsolete-coroutines-api/-obsolete-coroutines-api.html @@ -1,72 +1 @@ - - - - - ObsoleteCoroutinesApi - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

ObsoleteCoroutinesApi

-
-
-
-
fun ObsoleteCoroutinesApi()
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-obsolete-coroutines-api/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-obsolete-coroutines-api/index.html index a40db93b5e..88244f854e 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-obsolete-coroutines-api/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-obsolete-coroutines-api/index.html @@ -1,96 +1 @@ - - - - - ObsoleteCoroutinesApi - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

ObsoleteCoroutinesApi

-
-
-
annotation class ObsoleteCoroutinesApi

Marks declarations that are obsolete in coroutines API, which means that the design of the corresponding declarations has serious known flaws and they will be redesigned in the future. Roughly speaking, these declarations will be deprecated in the future but there is no replacement for them yet, so they cannot be deprecated right away.

-
-
-
-
-

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun ObsoleteCoroutinesApi()
-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-runnable.html b/kotlinx-coroutines-core/kotlinx.coroutines/-runnable.html index 450607255f..098753fc4e 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-runnable.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-runnable.html @@ -1,108 +1 @@ - - - - - Runnable - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Runnable

-
-
-
-
expect inline fun Runnable(crossinline block: () -> Unit): Runnable

Creates Runnable task instance.

actual inline fun Runnable(crossinline block: () -> Unit): Runnable

Creates Runnable task instance.

actual inline fun Runnable(crossinline block: () -> Unit): Runnable

Creates Runnable task instance.

actual inline fun Runnable(crossinline block: () -> Unit): Runnable

Creates Runnable task instance.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-runnable/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-runnable/index.html index 80ac9242c5..dcaee3b38d 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-runnable/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-runnable/index.html @@ -1,102 +1 @@ - - - - - Runnable - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Runnable

-
-
-
expect interface Runnable

A runnable task for CoroutineDispatcher.dispatch.

actual interface Runnable

A runnable task for CoroutineDispatcher.dispatch.

actual typealias Runnable = Runnable
actual interface Runnable

A runnable task for CoroutineDispatcher.dispatch.

-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-supervisor-job.html b/kotlinx-coroutines-core/kotlinx.coroutines/-supervisor-job.html index f52a5f5d6b..af6a1998ba 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-supervisor-job.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-supervisor-job.html @@ -1,72 +1 @@ - - - - - SupervisorJob - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

SupervisorJob

-
-
-
-
fun SupervisorJob(parent: Job? = null): CompletableJob

Creates a supervisor job object in an active state. Children of a supervisor job can fail independently of each other.

A failure or cancellation of a child does not cause the supervisor job to fail and does not affect its other children, so a supervisor can implement a custom policy for handling failures of its children:

If parent job is specified, then this supervisor job becomes a child job of its parent and is cancelled when its parent fails or is cancelled. All this supervisor's children are cancelled in this case, too. The invocation of cancel with exception (other than CancellationException) on this supervisor job also cancels parent.

Parameters

parent

an optional parent job.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-thread-context-element/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-thread-context-element/index.html index c5124d1bde..92d51d2bbd 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-thread-context-element/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-thread-context-element/index.html @@ -1,126 +1 @@ - - - - - ThreadContextElement - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

ThreadContextElement

-
-
-
interface ThreadContextElement<S> : CoroutineContext.Element

Defines elements in CoroutineContext that are installed into thread context every time the coroutine with this element in the context is resumed on a thread.

Implementations of this interface define a type S of the thread-local state that they need to store on resume of a coroutine and restore later on suspend. The infrastructure provides the corresponding storage.

Example usage looks like this:

// Appends "name" of a coroutine to a current thread name when coroutine is executed
class CoroutineName(val name: String) : ThreadContextElement<String> {
// declare companion object for a key of this element in coroutine context
companion object Key : CoroutineContext.Key<CoroutineName>

// provide the key of the corresponding context element
override val key: CoroutineContext.Key<CoroutineName>
get() = Key

// this is invoked before coroutine is resumed on current thread
override fun updateThreadContext(context: CoroutineContext): String {
val previousName = Thread.currentThread().name
Thread.currentThread().name = "$previousName # $name"
return previousName
}

// this is invoked after coroutine has suspended on current thread
override fun restoreThreadContext(context: CoroutineContext, oldState: String) {
Thread.currentThread().name = oldState
}
}

// Usage
launch(Dispatchers.Main + CoroutineName("Progress bar coroutine")) { ... }

Every time this coroutine is resumed on a thread, UI thread name is updated to "UI thread original name # Progress bar coroutine" and the thread name is restored to the original one when this coroutine suspends.

To use ThreadLocal variable within the coroutine use ThreadLocal.asContextElement function.

Reentrancy and thread-safety

Correct implementations of this interface must expect that calls to restoreThreadContext may happen in parallel to the subsequent updateThreadContext and restoreThreadContext operations. See CopyableThreadContextElement for advanced interleaving details.

All implementations of ThreadContextElement should be thread-safe and guard their internal mutable state within an element accordingly.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun restoreThreadContext(context: CoroutineContext, oldState: S)

Restores context of the current thread. This function is invoked after the coroutine in the specified context is suspended in the current thread if updateThreadContext was previously invoked on resume of this coroutine. The value of oldState is the result of the previous invocation of updateThreadContext and it should be restored in the thread-local state by this function. This method should handle its own exceptions and do not rethrow it. Thrown exceptions will leave coroutine which context is updated in an undefined state and may crash an application.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun updateThreadContext(context: CoroutineContext): S

Updates context of the current thread. This function is invoked before the coroutine in the specified context is resumed in the current thread when the context of the coroutine this element. The result of this function is the old value of the thread-local state that will be passed to restoreThreadContext. This method should handle its own exceptions and do not rethrow it. Thrown exceptions will leave coroutine which context is updated in an undefined state and may crash an application.

-
-
-
-
-
-

Inheritors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-thread-context-element/restore-thread-context.html b/kotlinx-coroutines-core/kotlinx.coroutines/-thread-context-element/restore-thread-context.html index abab32ee89..135dbbc357 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-thread-context-element/restore-thread-context.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-thread-context-element/restore-thread-context.html @@ -1,72 +1 @@ - - - - - restoreThreadContext - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

restoreThreadContext

-
-
-
-
abstract fun restoreThreadContext(context: CoroutineContext, oldState: S)

Restores context of the current thread. This function is invoked after the coroutine in the specified context is suspended in the current thread if updateThreadContext was previously invoked on resume of this coroutine. The value of oldState is the result of the previous invocation of updateThreadContext and it should be restored in the thread-local state by this function. This method should handle its own exceptions and do not rethrow it. Thrown exceptions will leave coroutine which context is updated in an undefined state and may crash an application.

Parameters

context

the coroutine context.

oldState

the value returned by the previous invocation of updateThreadContext.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-thread-context-element/update-thread-context.html b/kotlinx-coroutines-core/kotlinx.coroutines/-thread-context-element/update-thread-context.html index c425230222..54c4aebf5a 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-thread-context-element/update-thread-context.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-thread-context-element/update-thread-context.html @@ -1,72 +1 @@ - - - - - updateThreadContext - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

updateThreadContext

-
-
-
-
abstract fun updateThreadContext(context: CoroutineContext): S

Updates context of the current thread. This function is invoked before the coroutine in the specified context is resumed in the current thread when the context of the coroutine this element. The result of this function is the old value of the thread-local state that will be passed to restoreThreadContext. This method should handle its own exceptions and do not rethrow it. Thrown exceptions will leave coroutine which context is updated in an undefined state and may crash an application.

Parameters

context

the coroutine context.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-timeout-cancellation-exception/create-copy.html b/kotlinx-coroutines-core/kotlinx.coroutines/-timeout-cancellation-exception/create-copy.html index ba9a1ea417..566203a21d 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-timeout-cancellation-exception/create-copy.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-timeout-cancellation-exception/create-copy.html @@ -1,72 +1 @@ - - - - - createCopy - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

createCopy

-
-
-
-
open override fun createCopy(): TimeoutCancellationException?

Creates a copy of the current instance.

For better debuggability, it is recommended to use original exception as cause of the resulting one. Stacktrace of copied exception will be overwritten by stacktrace recovery machinery by Throwable.setStackTrace call. An exception can opt-out of copying by returning null from this function. Suppressed exceptions of the original exception should not be copied in order to avoid circular exceptions.

This function is allowed to create a copy with a modified message, but it should be noted that the copy can be later recovered as well and message modification code should handle this situation correctly (e.g. by also storing the original message and checking it) to produce a human-readable result.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/-timeout-cancellation-exception/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/-timeout-cancellation-exception/index.html index 6992b20cc7..dacafdf477 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/-timeout-cancellation-exception/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/-timeout-cancellation-exception/index.html @@ -1,96 +1 @@ - - - - - TimeoutCancellationException - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

TimeoutCancellationException

-
-
-

This exception is thrown by withTimeout to indicate timeout.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
open override fun createCopy(): TimeoutCancellationException?

Creates a copy of the current instance.

-
-
-
-
-
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/as-context-element.html b/kotlinx-coroutines-core/kotlinx.coroutines/as-context-element.html index 3c2b439ebf..ea93d969d9 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/as-context-element.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/as-context-element.html @@ -1,72 +1 @@ - - - - - asContextElement - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asContextElement

-
-
-
-
fun <T> ThreadLocal<T>.asContextElement(value: T = get()): ThreadContextElement<T>

Wraps ThreadLocal into ThreadContextElement. The resulting ThreadContextElement maintains the given value of the given ThreadLocal for coroutine regardless of the actual thread its is resumed on. By default ThreadLocal.get is used as a value for the thread-local variable, but it can be overridden with value parameter. Beware that context element does not track modifications of the thread-local and accessing thread-local from coroutine without the corresponding context element returns undefined value. See the examples for a detailed description.

Example usage:

val myThreadLocal = ThreadLocal<String?>()
...
println(myThreadLocal.get()) // Prints "null"
launch(Dispatchers.Default + myThreadLocal.asContextElement(value = "foo")) {
println(myThreadLocal.get()) // Prints "foo"
withContext(Dispatchers.Main) {
println(myThreadLocal.get()) // Prints "foo", but it's on UI thread
}
}
println(myThreadLocal.get()) // Prints "null"

The context element does not track modifications of the thread-local variable, for example:

myThreadLocal.set("main")
withContext(Dispatchers.Main) {
println(myThreadLocal.get()) // Prints "main"
myThreadLocal.set("UI")
}
println(myThreadLocal.get()) // Prints "main", not "UI"

Use withContext to update the corresponding thread-local variable to a different value, for example:

withContext(myThreadLocal.asContextElement("foo")) {
println(myThreadLocal.get()) // Prints "foo"
}

Accessing the thread-local without corresponding context element leads to undefined value:

val tl = ThreadLocal.withInitial { "initial" }

runBlocking {
println(tl.get()) // Will print "initial"
// Change context
withContext(tl.asContextElement("modified")) {
println(tl.get()) // Will print "modified"
}
// Context is changed again
println(tl.get()) // <- WARN: can print either "modified" or "initial"
}

to fix this behaviour use runBlocking(tl.asContextElement())

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/as-coroutine-dispatcher.html b/kotlinx-coroutines-core/kotlinx.coroutines/as-coroutine-dispatcher.html index 1be4b7bad8..fa5778700e 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/as-coroutine-dispatcher.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/as-coroutine-dispatcher.html @@ -1,95 +1 @@ - - - - - asCoroutineDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asCoroutineDispatcher

-
-
-
-
fun Window.asCoroutineDispatcher(): CoroutineDispatcher

Converts an instance of Window to an implementation of CoroutineDispatcher.

@JvmName(name = "from")
fun ExecutorService.asCoroutineDispatcher(): ExecutorCoroutineDispatcher

Converts an instance of ExecutorService to an implementation of ExecutorCoroutineDispatcher.

Interaction with delay and time-based coroutines.

If the given ExecutorService is an instance of ScheduledExecutorService, then all time-related coroutine operations such as delay, withTimeout and time-based Flow operators will be scheduled on this executor using schedule method. If the corresponding coroutine is cancelled, ScheduledFuture.cancel will be invoked on the corresponding future.

If the given ExecutorService is an instance of ScheduledThreadPoolExecutor, then prior to any scheduling, remove on cancel policy will be set via ScheduledThreadPoolExecutor.setRemoveOnCancelPolicy in order to reduce the memory pressure of cancelled coroutines.

If the executor service is neither of this types, the separate internal thread will be used to track the delay and time-related executions, but the coroutine itself will still be executed on top of the given executor.

Rejected execution

If the underlying executor throws RejectedExecutionException on attempt to submit a continuation task (it happens when closing the resulting dispatcher, on underlying executor shutdown, or when it uses limited queues), then the Job of the affected task is cancelled and the task is submitted to the Dispatchers.IO, so that the affected coroutine can cleanup its resources and promptly complete.


@JvmName(name = "from")
fun Executor.asCoroutineDispatcher(): CoroutineDispatcher

Converts an instance of Executor to an implementation of CoroutineDispatcher.

Interaction with delay and time-based coroutines.

If the given Executor is an instance of ScheduledExecutorService, then all time-related coroutine operations such as delay, withTimeout and time-based Flow operators will be scheduled on this executor using schedule method. If the corresponding coroutine is cancelled, ScheduledFuture.cancel will be invoked on the corresponding future.

If the given Executor is an instance of ScheduledThreadPoolExecutor, then prior to any scheduling, remove on cancel policy will be set via ScheduledThreadPoolExecutor.setRemoveOnCancelPolicy in order to reduce the memory pressure of cancelled coroutines.

If the executor is neither of this types, the separate internal thread will be used to track the delay and time-related executions, but the coroutine itself will still be executed on top of the given executor.

Rejected execution

If the underlying executor throws RejectedExecutionException on attempt to submit a continuation task (it happens when closing the resulting dispatcher, on underlying executor shutdown, or when it uses limited queues), then the Job of the affected task is cancelled and the task is submitted to the Dispatchers.IO, so that the affected coroutine can cleanup its resources and promptly complete.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/as-deferred.html b/kotlinx-coroutines-core/kotlinx.coroutines/as-deferred.html index b79dd269eb..d89360e44b 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/as-deferred.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/as-deferred.html @@ -1,72 +1 @@ - - - - - asDeferred - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asDeferred

-
-
-
-
fun <T> Promise<T>.asDeferred(): Deferred<T>

Converts this promise value to the instance of Deferred.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/as-executor.html b/kotlinx-coroutines-core/kotlinx.coroutines/as-executor.html index ddbf5f5a01..dd09b642f8 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/as-executor.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/as-executor.html @@ -1,72 +1 @@ - - - - - asExecutor - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asExecutor

-
-
-
-
fun CoroutineDispatcher.asExecutor(): Executor

Converts an instance of CoroutineDispatcher to an implementation of Executor.

It returns the original executor when used on the result of Executor.asCoroutineDispatcher extensions.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/as-promise.html b/kotlinx-coroutines-core/kotlinx.coroutines/as-promise.html index 3274f9c33a..f03a81dd8b 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/as-promise.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/as-promise.html @@ -1,72 +1 @@ - - - - - asPromise - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asPromise

-
-
-
-
fun <T> Deferred<T>.asPromise(): Promise<T>

Converts this deferred value to the instance of Promise.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/async.html b/kotlinx-coroutines-core/kotlinx.coroutines/async.html index 4c2f0110b3..c17e258537 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/async.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/async.html @@ -1,72 +1 @@ - - - - - async - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

async

-
-
-
-
fun <T> CoroutineScope.async(    context: CoroutineContext = EmptyCoroutineContext,     start: CoroutineStart = CoroutineStart.DEFAULT,     block: suspend CoroutineScope.() -> T): Deferred<T>

Creates a coroutine and returns its future result as an implementation of Deferred. The running coroutine is cancelled when the resulting deferred is cancelled. The resulting coroutine has a key difference compared with similar primitives in other languages and frameworks: it cancels the parent job (or outer scope) on failure to enforce structured concurrency paradigm. To change that behaviour, supervising parent (SupervisorJob or supervisorScope) can be used.

Coroutine context is inherited from a CoroutineScope, additional context elements can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. The parent job is inherited from a CoroutineScope as well, but it can also be overridden with corresponding context element.

By default, the coroutine is immediately scheduled for execution. Other options can be specified via start parameter. See CoroutineStart for details. An optional start parameter can be set to CoroutineStart.LAZY to start coroutine lazily. In this case, the resulting Deferred is created in new state. It can be explicitly started with start function and will be started implicitly on the first invocation of join, await or awaitAll.

Parameters

block

the coroutine code.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/await-all.html b/kotlinx-coroutines-core/kotlinx.coroutines/await-all.html index 0563486d24..b1bfa9e90f 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/await-all.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/await-all.html @@ -1,83 +1 @@ - - - - - awaitAll - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitAll

-
-
-
-
suspend fun <T> awaitAll(vararg deferreds: Deferred<T>): List<T>

Awaits for completion of given deferred values without blocking a thread and resumes normally with the list of values when all deferred computations are complete or resumes with the first thrown exception if any of computations complete exceptionally including cancellation.

This function is not equivalent to deferreds.map { it.await() } which fails only when it sequentially gets to wait for the failing deferred, while this awaitAll fails immediately as soon as any of the deferreds fail.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this suspending function is waiting, this function immediately resumes with CancellationException. There is a prompt cancellation guarantee. If the job was cancelled while this function was suspended, it will not resume successfully. See suspendCancellableCoroutine documentation for low-level details.


suspend fun <T> Collection<Deferred<T>>.awaitAll(): List<T>

Awaits for completion of given deferred values without blocking a thread and resumes normally with the list of values when all deferred computations are complete or resumes with the first thrown exception if any of computations complete exceptionally including cancellation.

This function is not equivalent to this.map { it.await() } which fails only when it sequentially gets to wait for the failing deferred, while this awaitAll fails immediately as soon as any of the deferreds fail.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this suspending function is waiting, this function immediately resumes with CancellationException. There is a prompt cancellation guarantee. If the job was cancelled while this function was suspended, it will not resume successfully. See suspendCancellableCoroutine documentation for low-level details.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/await-animation-frame.html b/kotlinx-coroutines-core/kotlinx.coroutines/await-animation-frame.html index 8d080b9fa3..9a6b409c3c 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/await-animation-frame.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/await-animation-frame.html @@ -1,72 +1 @@ - - - - - awaitAnimationFrame - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitAnimationFrame

-
-
-
-
suspend fun Window.awaitAnimationFrame(): Double

Suspends coroutine until next JS animation frame and returns frame time on resumption. The time is consistent with window.performance.now(). This function is cancellable. If the Job of the current coroutine is completed while this suspending function is waiting, this function immediately resumes with CancellationException.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/await-cancellation.html b/kotlinx-coroutines-core/kotlinx.coroutines/await-cancellation.html index c338f41c97..9033969481 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/await-cancellation.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/await-cancellation.html @@ -1,72 +1 @@ - - - - - awaitCancellation - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitCancellation

-
-
-
-
suspend fun awaitCancellation(): Nothing

Suspends until cancellation, in which case it will throw a CancellationException.

This function returns Nothing, so it can be used in any coroutine, regardless of the required return type.

Usage example in callback adapting code:

fun currentTemperature(): Flow<Temperature> = callbackFlow {
val callback = SensorCallback { degreesCelsius: Double ->
trySend(Temperature.celsius(degreesCelsius))
}
try {
registerSensorCallback(callback)
awaitCancellation() // Suspends to keep getting updates until cancellation.
} finally {
unregisterSensorCallback(callback)
}
}

Usage example in (non declarative) UI code:

suspend fun showStuffUntilCancelled(content: Stuff): Nothing {
someSubView.text = content.title
anotherSubView.text = content.description
someView.visibleInScope {
awaitCancellation() // Suspends so the view stays visible.
}
}
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/await.html b/kotlinx-coroutines-core/kotlinx.coroutines/await.html index 81126b797c..3ff957e993 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/await.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/await.html @@ -1,72 +1 @@ - - - - - await - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

await

-
-
-
-
suspend fun <T> Promise<T>.await(): T

Awaits for completion of the promise without blocking.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this suspending function is waiting, this function stops waiting for the promise and immediately resumes with CancellationException. There is a prompt cancellation guarantee. If the job was cancelled while this function was suspended, it will not resume successfully. See suspendCancellableCoroutine documentation for low-level details.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/cancel-and-join.html b/kotlinx-coroutines-core/kotlinx.coroutines/cancel-and-join.html index bf6d87547e..4ba3b3e1d3 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/cancel-and-join.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/cancel-and-join.html @@ -1,72 +1 @@ - - - - - cancelAndJoin - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

cancelAndJoin

-
-
-
-
suspend fun Job.cancelAndJoin()

Cancels the job and suspends the invoking coroutine until the cancelled job is complete.

This suspending function is cancellable and always checks for a cancellation of the invoking coroutine's Job. If the Job of the invoking coroutine is cancelled or completed when this suspending function is invoked or while it is suspended, this function throws CancellationException.

In particular, it means that a parent coroutine invoking cancelAndJoin on a child coroutine throws CancellationException if the child had failed, since a failure of a child coroutine cancels parent by default, unless the child was launched from within supervisorScope.

This is a shortcut for the invocation of cancel followed by join.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/cancel-children.html b/kotlinx-coroutines-core/kotlinx.coroutines/cancel-children.html index 679fe5d676..f5fa9ea8b0 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/cancel-children.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/cancel-children.html @@ -1,83 +1 @@ - - - - - cancelChildren - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

cancelChildren

-
-
-
-
fun Job.cancelChildren(cause: CancellationException? = null)

Cancels all children jobs of this coroutine using Job.cancel for all of them with an optional cancellation cause. Unlike Job.cancel on this job as a whole, the state of this job itself is not affected.


fun CoroutineContext.cancelChildren(cause: CancellationException? = null)

Cancels all children of the Job in this context, without touching the state of this job itself with an optional cancellation cause. See Job.cancel. It does not do anything if there is no job in the context or it has no children.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/cancel-future-on-cancellation.html b/kotlinx-coroutines-core/kotlinx.coroutines/cancel-future-on-cancellation.html index 38de6171ee..833d68f119 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/cancel-future-on-cancellation.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/cancel-future-on-cancellation.html @@ -1,72 +1 @@ - - - - - cancelFutureOnCancellation - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

cancelFutureOnCancellation

-
-
-
-
fun CancellableContinuation<*>.cancelFutureOnCancellation(future: Future<*>)

Cancels a specified future when this job is cancelled. This is a shortcut for the following code with slightly more efficient implementation (one fewer object created).

invokeOnCancellation { if (it != null) future.cancel(false) }
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/cancel.html b/kotlinx-coroutines-core/kotlinx.coroutines/cancel.html index 382a123db4..bd62f4e842 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/cancel.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/cancel.html @@ -1,105 +1 @@ - - - - - cancel - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

cancel

-
-
-
-
fun CoroutineScope.cancel(cause: CancellationException? = null)

Cancels this scope, including its job and all its children with an optional cancellation cause. A cause can be used to specify an error message or to provide other details on a cancellation reason for debugging purposes. Throws IllegalStateException if the scope does not have a job in it.


fun CoroutineScope.cancel(message: String, cause: Throwable? = null)

Cancels this scope, including its job and all its children with a specified diagnostic error message. A cause can be specified to provide additional details on a cancellation reason for debugging purposes. Throws IllegalStateException if the scope does not have a job in it.


fun CoroutineContext.cancel(cause: CancellationException? = null)

Cancels Job of this context with an optional cancellation cause. See Job.cancel for details.


fun Job.cancel(message: String, cause: Throwable? = null)

Cancels current job, including all its children with a specified diagnostic error message. A cause can be specified to provide additional details on a cancellation reason for debugging purposes.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/complete-with.html b/kotlinx-coroutines-core/kotlinx.coroutines/complete-with.html index 663fd34e41..6a79b82198 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/complete-with.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/complete-with.html @@ -1,72 +1 @@ - - - - - completeWith - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

completeWith

-
-
-
-
fun <T> CompletableDeferred<T>.completeWith(result: Result<T>): Boolean

Completes this deferred value with the value or exception in the given result. Returns true if this deferred was completed as a result of this invocation and false otherwise (if it was already completed).

Subsequent invocations of this function have no effect and always produce false.

This function transitions this deferred in the same ways described by CompletableDeferred.complete and CompletableDeferred.completeExceptionally.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/coroutine-scope.html b/kotlinx-coroutines-core/kotlinx.coroutines/coroutine-scope.html index 98f569dde8..9df523ff13 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/coroutine-scope.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/coroutine-scope.html @@ -1,72 +1 @@ - - - - - coroutineScope - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

coroutineScope

-
-
-
-
suspend fun <R> coroutineScope(block: suspend CoroutineScope.() -> R): R

Creates a CoroutineScope and calls the specified suspend block with this scope. The provided scope inherits its coroutineContext from the outer scope, but overrides the context's Job.

This function is designed for parallel decomposition of work. When any child coroutine in this scope fails, this scope fails and all the rest of the children are cancelled (for a different behavior see supervisorScope). This function returns as soon as the given block and all its children coroutines are completed. A usage example of a scope looks like this:

suspend fun showSomeData() = coroutineScope {
val data = async(Dispatchers.IO) { // <- extension on current scope
... load some UI data for the Main thread ...
}

withContext(Dispatchers.Main) {
doSomeWork()
val result = data.await()
display(result)
}
}

The scope in this example has the following semantics:

  1. showSomeData returns as soon as the data is loaded and displayed in the UI.

  2. If doSomeWork throws an exception, then the async task is cancelled and showSomeData rethrows that exception.

  3. If the outer scope of showSomeData is cancelled, both started async and withContext blocks are cancelled.

  4. If the async block fails, withContext will be cancelled.

The method may throw a CancellationException if the current job was cancelled externally or may throw a corresponding unhandled Throwable if there is any unhandled exception in this scope (for example, from a crashed coroutine that was started with launch in this scope).

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/current-coroutine-context.html b/kotlinx-coroutines-core/kotlinx.coroutines/current-coroutine-context.html index 4ed8152e2e..0ef452e808 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/current-coroutine-context.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/current-coroutine-context.html @@ -1,72 +1 @@ - - - - - currentCoroutineContext - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

currentCoroutineContext

-
-
-
-
inline suspend fun currentCoroutineContext(): CoroutineContext

Returns the current CoroutineContext retrieved by using kotlin.coroutines.coroutineContext. This function is an alias to avoid name clash with CoroutineScope.coroutineContext in a receiver position:

launch { // this: CoroutineScope
val flow = flow<Unit> {
coroutineContext // Resolves into the context of outer launch, which is incorrect, see KT-38033
currentCoroutineContext() // Retrieves actual context where the flow is collected
}
}
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/delay.html b/kotlinx-coroutines-core/kotlinx.coroutines/delay.html index 240775515e..4b27ce71b2 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/delay.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/delay.html @@ -1,83 +1 @@ - - - - - delay - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

delay

-
-
-
-
suspend fun delay(timeMillis: Long)

Delays coroutine for a given time without blocking a thread and resumes it after a specified time.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this suspending function is waiting, this function immediately resumes with CancellationException. There is a prompt cancellation guarantee. If the job was cancelled while this function was suspended, it will not resume successfully. See suspendCancellableCoroutine documentation for low-level details.

If you want to delay forever (until cancellation), consider using awaitCancellation instead.

Note that delay can be used in select invocation with onTimeout clause.

Implementation note: how exactly time is tracked is an implementation detail of CoroutineDispatcher in the context.

Parameters

timeMillis

time in milliseconds.


suspend fun delay(duration: Duration)

Delays coroutine for a given duration without blocking a thread and resumes it after the specified time.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this suspending function is waiting, this function immediately resumes with CancellationException. There is a prompt cancellation guarantee. If the job was cancelled while this function was suspended, it will not resume successfully. See suspendCancellableCoroutine documentation for low-level details.

If you want to delay forever (until cancellation), consider using awaitCancellation instead.

Note that delay can be used in select invocation with onTimeout clause.

Implementation note: how exactly time is tracked is an implementation detail of CoroutineDispatcher in the context.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/ensure-active.html b/kotlinx-coroutines-core/kotlinx.coroutines/ensure-active.html index dcf4f3f686..be1af6cea7 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/ensure-active.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/ensure-active.html @@ -1,94 +1 @@ - - - - - ensureActive - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

ensureActive

-
-
-
-
fun CoroutineScope.ensureActive()

Ensures that current scope is active.

If the job is no longer active, throws CancellationException. If the job was cancelled, thrown exception contains the original cancellation cause. This function does not do anything if there is no Job in the scope's coroutineContext.

This method is a drop-in replacement for the following code, but with more precise exception:

if (!isActive) {
throw CancellationException()
}

See also


fun Job.ensureActive()

Ensures that current job is active. If the job is no longer active, throws CancellationException. If the job was cancelled, thrown exception contains the original cancellation cause.

This method is a drop-in replacement for the following code, but with more precise exception:

if (!job.isActive) {
throw CancellationException()
}

fun CoroutineContext.ensureActive()

Ensures that job in the current context is active.

If the job is no longer active, throws CancellationException. If the job was cancelled, thrown exception contains the original cancellation cause. This function does not do anything if there is no Job in the context, since such a coroutine cannot be cancelled.

This method is a drop-in replacement for the following code, but with more precise exception:

if (!isActive) {
throw CancellationException()
}
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/ensure-present.html b/kotlinx-coroutines-core/kotlinx.coroutines/ensure-present.html index de82d49eb4..fea0f178bb 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/ensure-present.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/ensure-present.html @@ -1,72 +1 @@ - - - - - ensurePresent - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

ensurePresent

-
-
-
-
inline suspend fun ThreadLocal<*>.ensurePresent()

Checks whether current thread local is present in the coroutine context and throws IllegalStateException if it is not. It is a good practice to validate that thread local is present in the context, especially in large code-bases, to avoid stale thread-local values and to have a strict invariants.

E.g. one may use the following method to enforce proper use of the thread locals with coroutines:

public suspend inline fun <T> ThreadLocal<T>.getSafely(): T {
ensurePresent()
return get()
}

// Usage
withContext(...) {
val value = threadLocal.getSafely() // Fail-fast in case of improper context
}
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/handle-coroutine-exception.html b/kotlinx-coroutines-core/kotlinx.coroutines/handle-coroutine-exception.html index 34da49bdcf..cf9f81ce6d 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/handle-coroutine-exception.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/handle-coroutine-exception.html @@ -1,72 +1 @@ - - - - - handleCoroutineException - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

handleCoroutineException

-
-
-
-
fun handleCoroutineException(context: CoroutineContext, exception: Throwable)

Helper function for coroutine builder implementations to handle uncaught and unexpected exceptions in coroutines, that could not be otherwise handled in a normal way through structured concurrency, saving them to a future, and cannot be rethrown. This is a last resort handler to prevent lost exceptions.

If there is CoroutineExceptionHandler in the context, then it is used. If it throws an exception during handling or is absent, all instances of CoroutineExceptionHandler found via ServiceLoader and Thread.uncaughtExceptionHandler are invoked.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/index.html b/kotlinx-coroutines-core/kotlinx.coroutines/index.html index d0a4230205..ab0953a74a 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/index.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/index.html @@ -1,1451 +1 @@ - - - - - kotlinx.coroutines - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Package kotlinx.coroutines

-
-
-

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

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

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

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

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

-
-
-
-
-

Types

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface CancellableContinuation<in T> : Continuation<T>

Cancellable continuation. It is completed when resumed or cancelled. When the cancel function is explicitly invoked, this continuation immediately resumes with a CancellationException or the specified cancel cause.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
expect open class CancellationException(message: String?) : IllegalStateException
actual typealias CancellationException = CancellationException
actual typealias CancellationException = CancellationException
actual typealias CancellationException = CancellationException
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
expect abstract class CloseableCoroutineDispatcher : CoroutineDispatcher

CoroutineDispatcher that provides a method to close it, causing the rejection of any new tasks and cleanup of all underlying resources associated with the current dispatcher. Examples of closeable dispatchers are dispatchers backed by java.lang.Executor and by kotlin.native.Worker.

actual abstract class CloseableCoroutineDispatcher : CoroutineDispatcher
actual typealias CloseableCoroutineDispatcher = ExecutorCoroutineDispatcher
actual abstract class CloseableCoroutineDispatcher : CoroutineDispatcher
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface CompletableDeferred<T> : Deferred<T>

A Deferred that can be completed via public functions complete or cancel.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface CompletableJob : Job

A job that can be completed using complete() function. It is returned by Job() and SupervisorJob() constructor functions.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
typealias CompletionHandler = (cause: Throwable?) -> Unit

Handler for Job.invokeOnCompletion and CancellableContinuation.invokeOnCancellation.

Installed handler should not throw any exceptions. If it does, they will get caught, wrapped into CompletionHandlerException, and rethrown, potentially causing crash of unrelated code.

The meaning of cause that is passed to the handler:

  • Cause is null when the job has completed normally.

  • Cause is an instance of CancellationException when the job was cancelled normally. It should not be treated as an error. In particular, it should not be reported to error logs.

  • Otherwise, the job had failed.

Note: This type is a part of internal machinery that supports parent-child hierarchies and allows for implementation of suspending functions that wait on the Job's state. This type should not be used in general application code. Implementations of CompletionHandler must be fast and lock-free.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

A ThreadContextElement copied whenever a child coroutine inherits a context containing it.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface CopyableThrowable<T : Throwable, CopyableThrowable<T>>

Throwable which can be cloned during stacktrace recovery in a class-specific way. For additional information about stacktrace recovery see STACKTRACE_RECOVERY_PROPERTY_NAME

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Base class to be extended by all coroutine dispatcher implementations.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface CoroutineExceptionHandler : CoroutineContext.Element

An optional element in the coroutine context to handle uncaught exceptions.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
data class CoroutineName(val name: String) : AbstractCoroutineContextElement

User-specified name of coroutine. This name is used in debugging mode. See newCoroutineContext for the description of coroutine debugging facilities.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface CoroutineScope

Defines a scope for new coroutines. Every coroutine builder (like launch, async, etc.) is an extension on CoroutineScope and inherits its coroutineContext to automatically propagate all its elements and cancellation.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
enum CoroutineStart : Enum<CoroutineStart>

Defines start options for coroutines builders. It is used in start parameter of launch, async, and other coroutine builder functions.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface Deferred<out T> : Job

Deferred value is a non-blocking cancellable future — it is a Job with a result.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
annotation class DelicateCoroutinesApi

Marks declarations in the coroutines that are delicate — they have limited use-case and shall be used with care in general code. Any use of a delicate declaration has to be carefully reviewed to make sure it is properly used and does not create problems like memory and resource leaks. Carefully read documentation of any declaration marked as DelicateCoroutinesApi.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
expect object Dispatchers

Groups various implementations of CoroutineDispatcher.

actual object Dispatchers
actual object Dispatchers

Groups various implementations of CoroutineDispatcher.

actual object Dispatchers
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun interface DisposableHandle

A handle to an allocated object that can be disposed to make it eligible for garbage collection.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract class ExecutorCoroutineDispatcher : CoroutineDispatcher, Closeable

CoroutineDispatcher that has underlying Executor for dispatching tasks. Instances of ExecutorCoroutineDispatcher should be closed by the owner of the dispatcher.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Marks declarations that are still experimental in coroutines API, which means that the design of the corresponding declarations has open issues which may (or may not) lead to their changes in the future. Roughly speaking, there is a chance that those declarations will be deprecated in the near future or the semantics of their behavior may change in some way that may break some code.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Marks Flow-related API as a feature preview.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
object GlobalScope : CoroutineScope

A global CoroutineScope not bound to any job. Global scope is used to launch top-level coroutines which are operating on the whole application lifetime and are not cancelled prematurely.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Marks declarations that are internal in coroutines API, which means that should not be used outside of kotlinx.coroutines, because their signatures and semantics will change between future releases without any warnings and without providing any migration aids.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface Job : CoroutineContext.Element

A background job. Conceptually, a job is a cancellable thing with a life-cycle that culminates in its completion.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract class MainCoroutineDispatcher : CoroutineDispatcher

Base class for special CoroutineDispatcher which is confined to application "Main" or "UI" thread and used for any UI-based activities. Instance of MainDispatcher can be obtained by Dispatchers.Main.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
object NonCancellable : AbstractCoroutineContextElement, Job

A non-cancelable job that is always active. It is designed for withContext function to prevent cancellation of code blocks that need to be executed without cancellation.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
annotation class ObsoleteCoroutinesApi

Marks declarations that are obsolete in coroutines API, which means that the design of the corresponding declarations has serious known flaws and they will be redesigned in the future. Roughly speaking, these declarations will be deprecated in the future but there is no replacement for them yet, so they cannot be deprecated right away.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
expect interface Runnable

A runnable task for CoroutineDispatcher.dispatch.

actual interface Runnable

A runnable task for CoroutineDispatcher.dispatch.

actual typealias Runnable = Runnable
actual interface Runnable

A runnable task for CoroutineDispatcher.dispatch.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface ThreadContextElement<S> : CoroutineContext.Element

Defines elements in CoroutineContext that are installed into thread context every time the coroutine with this element in the context is resumed on a thread.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

This exception is thrown by withTimeout to indicate timeout.

-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> ThreadLocal<T>.asContextElement(value: T = get()): ThreadContextElement<T>

Wraps ThreadLocal into ThreadContextElement. The resulting ThreadContextElement maintains the given value of the given ThreadLocal for coroutine regardless of the actual thread its is resumed on. By default ThreadLocal.get is used as a value for the thread-local variable, but it can be overridden with value parameter. Beware that context element does not track modifications of the thread-local and accessing thread-local from coroutine without the corresponding context element returns undefined value. See the examples for a detailed description.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun Window.asCoroutineDispatcher(): CoroutineDispatcher

Converts an instance of Window to an implementation of CoroutineDispatcher.

@JvmName(name = "from")
fun Executor.asCoroutineDispatcher(): CoroutineDispatcher

Converts an instance of Executor to an implementation of CoroutineDispatcher.

@JvmName(name = "from")
fun ExecutorService.asCoroutineDispatcher(): ExecutorCoroutineDispatcher

Converts an instance of ExecutorService to an implementation of ExecutorCoroutineDispatcher.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Promise<T>.asDeferred(): Deferred<T>

Converts this promise value to the instance of Deferred.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun CoroutineDispatcher.asExecutor(): Executor

Converts an instance of CoroutineDispatcher to an implementation of Executor.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> Deferred<T>.asPromise(): Promise<T>

Converts this deferred value to the instance of Promise.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> CoroutineScope.async(    context: CoroutineContext = EmptyCoroutineContext,     start: CoroutineStart = CoroutineStart.DEFAULT,     block: suspend CoroutineScope.() -> T): Deferred<T>

Creates a coroutine and returns its future result as an implementation of Deferred. The running coroutine is cancelled when the resulting deferred is cancelled. The resulting coroutine has a key difference compared with similar primitives in other languages and frameworks: it cancels the parent job (or outer scope) on failure to enforce structured concurrency paradigm. To change that behaviour, supervising parent (SupervisorJob or supervisorScope) can be used.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> Promise<T>.await(): T

Awaits for completion of the promise without blocking.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> Collection<Deferred<T>>.awaitAll(): List<T>
suspend fun <T> awaitAll(vararg deferreds: Deferred<T>): List<T>

Awaits for completion of given deferred values without blocking a thread and resumes normally with the list of values when all deferred computations are complete or resumes with the first thrown exception if any of computations complete exceptionally including cancellation.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun Window.awaitAnimationFrame(): Double

Suspends coroutine until next JS animation frame and returns frame time on resumption. The time is consistent with window.performance.now(). This function is cancellable. If the Job of the current coroutine is completed while this suspending function is waiting, this function immediately resumes with CancellationException.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun awaitCancellation(): Nothing

Suspends until cancellation, in which case it will throw a CancellationException.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun CoroutineContext.cancel(cause: CancellationException? = null)

Cancels Job of this context with an optional cancellation cause. See Job.cancel for details.

fun CoroutineScope.cancel(cause: CancellationException? = null)

Cancels this scope, including its job and all its children with an optional cancellation cause. A cause can be used to specify an error message or to provide other details on a cancellation reason for debugging purposes. Throws IllegalStateException if the scope does not have a job in it.

fun CoroutineScope.cancel(message: String, cause: Throwable? = null)

Cancels this scope, including its job and all its children with a specified diagnostic error message. A cause can be specified to provide additional details on a cancellation reason for debugging purposes. Throws IllegalStateException if the scope does not have a job in it.

fun Job.cancel(message: String, cause: Throwable? = null)

Cancels current job, including all its children with a specified diagnostic error message. A cause can be specified to provide additional details on a cancellation reason for debugging purposes.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun Job.cancelAndJoin()

Cancels the job and suspends the invoking coroutine until the cancelled job is complete.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun CoroutineContext.cancelChildren(cause: CancellationException? = null)

Cancels all children of the Job in this context, without touching the state of this job itself with an optional cancellation cause. See Job.cancel. It does not do anything if there is no job in the context or it has no children.

fun Job.cancelChildren(cause: CancellationException? = null)

Cancels all children jobs of this coroutine using Job.cancel for all of them with an optional cancellation cause. Unlike Job.cancel on this job as a whole, the state of this job itself is not affected.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun CancellableContinuation<*>.cancelFutureOnCancellation(future: Future<*>)

Cancels a specified future when this job is cancelled. This is a shortcut for the following code with slightly more efficient implementation (one fewer object created).

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
expect fun CancellationException(message: String?, cause: Throwable?): CancellationException
actual fun CancellationException(message: String?, cause: Throwable?): CancellationException

Creates a cancellation exception with a specified message and cause.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> CompletableDeferred(value: T): CompletableDeferred<T>

Creates an already completedCompletableDeferred with a given value.

fun <T> CompletableDeferred(parent: Job? = null): CompletableDeferred<T>

Creates a CompletableDeferred in an active state. It is optionally a child of a parent job.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> CompletableDeferred<T>.completeWith(result: Result<T>): Boolean

Completes this deferred value with the value or exception in the given result. Returns true if this deferred was completed as a result of this invocation and false otherwise (if it was already completed).

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline fun CoroutineExceptionHandler(crossinline handler: (CoroutineContext, Throwable) -> Unit): CoroutineExceptionHandler

Creates a CoroutineExceptionHandler instance.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <R> coroutineScope(block: suspend CoroutineScope.() -> R): R

Creates a CoroutineScope and calls the specified suspend block with this scope. The provided scope inherits its coroutineContext from the outer scope, but overrides the context's Job.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline suspend fun currentCoroutineContext(): CoroutineContext

Returns the current CoroutineContext retrieved by using kotlin.coroutines.coroutineContext. This function is an alias to avoid name clash with CoroutineScope.coroutineContext in a receiver position:

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun delay(timeMillis: Long)

Delays coroutine for a given time without blocking a thread and resumes it after a specified time.

suspend fun delay(duration: Duration)

Delays coroutine for a given duration without blocking a thread and resumes it after the specified time.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun CoroutineContext.ensureActive()

Ensures that job in the current context is active.

fun CoroutineScope.ensureActive()

Ensures that current scope is active.

fun Job.ensureActive()

Ensures that current job is active. If the job is no longer active, throws CancellationException. If the job was cancelled, thrown exception contains the original cancellation cause.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline suspend fun ThreadLocal<*>.ensurePresent()

Checks whether current thread local is present in the coroutine context and throws IllegalStateException if it is not. It is a good practice to validate that thread local is present in the context, especially in large code-bases, to avoid stale thread-local values and to have a strict invariants.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun handleCoroutineException(context: CoroutineContext, exception: Throwable)

Helper function for coroutine builder implementations to handle uncaught and unexpected exceptions in coroutines, that could not be otherwise handled in a normal way through structured concurrency, saving them to a future, and cannot be rethrown. This is a last resort handler to prevent lost exceptions.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline suspend operator fun <T> CoroutineDispatcher.invoke(noinline block: suspend CoroutineScope.() -> T): T

Calls the specified suspending block with the given CoroutineDispatcher, suspends until it completes, and returns the result.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline suspend fun ThreadLocal<*>.isPresent(): Boolean

Return true when current thread local is present in the coroutine context, false otherwise. Thread local can be present in the context only if it was added via asContextElement to the context.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun Job(parent: Job? = null): CompletableJob

Creates a job object in an active state. A failure of any child of this job immediately causes this job to fail, too, and cancels the rest of its children.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun Collection<Job>.joinAll()

Suspends current coroutine until all given jobs are complete. This method is semantically equivalent to joining all given jobs one by one with forEach { it.join() }.

suspend fun joinAll(vararg jobs: Job)

Suspends current coroutine until all given jobs are complete. This method is semantically equivalent to joining all given jobs one by one with jobs.forEach { it.join() }.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun CoroutineScope.launch(    context: CoroutineContext = EmptyCoroutineContext,     start: CoroutineStart = CoroutineStart.DEFAULT,     block: suspend CoroutineScope.() -> Unit): Job

Launches a new coroutine without blocking the current thread and returns a reference to the coroutine as a Job. The coroutine is cancelled when the resulting job is cancelled.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun MainScope(): CoroutineScope

Creates the main CoroutineScope for UI components.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
expect fun CoroutineScope.newCoroutineContext(context: CoroutineContext): CoroutineContext

Creates a context for a new coroutine. It installs Dispatchers.Default when no other dispatcher or ContinuationInterceptor is specified and adds optional support for debugging facilities (when turned on) and copyable-thread-local facilities on JVM.

actual fun CoroutineScope.newCoroutineContext(context: CoroutineContext): CoroutineContext

Creates a context for a new coroutine. It installs Dispatchers.Default when no other dispatcher or ContinuationInterceptor is specified and adds optional support for debugging facilities (when turned on) and copyable-thread-local facilities on JVM. See DEBUG_PROPERTY_NAME for description of debugging facilities on JVM.

actual fun CoroutineScope.newCoroutineContext(context: CoroutineContext): CoroutineContext
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
expect fun newFixedThreadPoolContext(nThreads: Int, name: String): CloseableCoroutineDispatcher
actual fun newFixedThreadPoolContext(nThreads: Int, name: String): CloseableCoroutineDispatcher

Creates a coroutine execution context with the fixed-size thread-pool and built-in yield support. NOTE: The resulting ExecutorCoroutineDispatcher owns native resources (its threads). Resources are reclaimed by ExecutorCoroutineDispatcher.close.

actual fun newFixedThreadPoolContext(nThreads: Int, name: String): CloseableCoroutineDispatcher
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Creates a coroutine execution context using a single thread with built-in yield support. NOTE: The resulting ExecutorCoroutineDispatcher owns native resources (its thread). Resources are reclaimed by ExecutorCoroutineDispatcher.close.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
operator fun CoroutineScope.plus(context: CoroutineContext): CoroutineScope

Adds the specified coroutine context to this scope, overriding existing elements in the current scope's context with the corresponding keys.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun <T> CoroutineScope.promise(    context: CoroutineContext = EmptyCoroutineContext,     start: CoroutineStart = CoroutineStart.DEFAULT,     block: suspend CoroutineScope.() -> T): Promise<T>

Starts new coroutine and returns its result as an implementation of Promise.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
expect fun <T> runBlocking(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): T

Runs a new coroutine and blocks the current thread until its completion. This function should not be used from a coroutine. It is designed to bridge regular blocking code to libraries that are written in suspending style, to be used in main functions and in tests.

actual fun <T> runBlocking(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): T

Runs a new coroutine and blocks the current thread interruptibly until its completion. This function should not be used from a coroutine. It is designed to bridge regular blocking code to libraries that are written in suspending style, to be used in main functions and in tests.

actual fun <T> runBlocking(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): T

Runs new coroutine and blocks current thread interruptibly until its completion. This function should not be used from coroutine. It is designed to bridge regular blocking code to libraries that are written in suspending style, to be used in main functions and in tests.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> runInterruptible(context: CoroutineContext = EmptyCoroutineContext, block: () -> T): T

Calls the specified block with a given coroutine context in an interruptible manner. The blocking code block will be interrupted and this function will throw CancellationException if the coroutine is cancelled.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
expect inline fun Runnable(crossinline block: () -> Unit): Runnable

Creates Runnable task instance.

actual inline fun Runnable(crossinline block: () -> Unit): Runnable

Creates Runnable task instance.

actual inline fun Runnable(crossinline block: () -> Unit): Runnable

Creates Runnable task instance.

actual inline fun Runnable(crossinline block: () -> Unit): Runnable

Creates Runnable task instance.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun SupervisorJob(parent: Job? = null): CompletableJob

Creates a supervisor job object in an active state. Children of a supervisor job can fail independently of each other.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <R> supervisorScope(block: suspend CoroutineScope.() -> R): R

Creates a CoroutineScope with SupervisorJob and calls the specified suspend block with this scope. The provided scope inherits its coroutineContext from the outer scope, but overrides context's Job with SupervisorJob. This function returns as soon as the given block and all its child coroutines are completed.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
inline suspend fun <T> suspendCancellableCoroutine(crossinline block: (CancellableContinuation<T>) -> Unit): T

Suspends the coroutine like suspendCoroutine, but providing a CancellableContinuation to the block. This function throws a CancellationException if the Job of the coroutine is cancelled or completed while it is suspended.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> withContext(context: CoroutineContext, block: suspend CoroutineScope.() -> T): T

Calls the specified suspending block with a given coroutine context, suspends until it completes, and returns the result.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> withTimeout(timeMillis: Long, block: suspend CoroutineScope.() -> T): T

Runs a given suspending block of code inside a coroutine with a specified timeout and throws a TimeoutCancellationException if the timeout was exceeded.

suspend fun <T> withTimeout(timeout: Duration, block: suspend CoroutineScope.() -> T): T

Runs a given suspending block of code inside a coroutine with the specified timeout and throws a TimeoutCancellationException if the timeout was exceeded.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun <T> withTimeoutOrNull(timeMillis: Long, block: suspend CoroutineScope.() -> T): T?

Runs a given suspending block of code inside a coroutine with a specified timeout and returns null if this timeout was exceeded.

suspend fun <T> withTimeoutOrNull(timeout: Duration, block: suspend CoroutineScope.() -> T): T?

Runs a given suspending block of code inside a coroutine with the specified timeout and returns null if this timeout was exceeded.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun yield()

Yields the thread (or thread pool) of the current coroutine dispatcher to other coroutines on the same dispatcher to run if possible.

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
const val DEBUG_PROPERTY_NAME: String

Name of the property that controls coroutine debugging.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
const val DEBUG_PROPERTY_VALUE_AUTO: String

Automatic debug configuration value for DEBUG_PROPERTY_NAME.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
const val DEBUG_PROPERTY_VALUE_OFF: String

Debug turned on value for DEBUG_PROPERTY_NAME.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
const val DEBUG_PROPERTY_VALUE_ON: String

Debug turned on value for DEBUG_PROPERTY_NAME.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
const val IO_PARALLELISM_PROPERTY_NAME: String

Name of the property that defines the maximal number of threads that are used by Dispatchers.IO coroutines dispatcher.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
val CoroutineScope.isActive: Boolean

Returns true when the current Job is still active (has not completed and was not cancelled yet).

val CoroutineContext.isActive: Boolean

Returns true when the Job of the coroutine in this context is still active (has not completed and was not cancelled yet).

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
val CoroutineContext.job: Job

Retrieves the current Job instance from the given CoroutineContext or throws IllegalStateException if no job is present in the context.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/invoke.html b/kotlinx-coroutines-core/kotlinx.coroutines/invoke.html index 0937c336c7..f6a96f4361 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/invoke.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/invoke.html @@ -1,72 +1 @@ - - - - - invoke - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

invoke

-
-
-
-
inline suspend operator fun <T> CoroutineDispatcher.invoke(noinline block: suspend CoroutineScope.() -> T): T

Calls the specified suspending block with the given CoroutineDispatcher, suspends until it completes, and returns the result.

This inline function calls withContext.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/is-active.html b/kotlinx-coroutines-core/kotlinx.coroutines/is-active.html index b589f87e4a..ff5a0abaca 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/is-active.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/is-active.html @@ -1,83 +1 @@ - - - - - isActive - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

isActive

-
-
-
-
val CoroutineScope.isActive: Boolean

Returns true when the current Job is still active (has not completed and was not cancelled yet).

Check this property in long-running computation loops to support cancellation:

while (isActive) {
// do some computation
}

This property is a shortcut for coroutineContext.isActive in the scope when CoroutineScope is available. See coroutineContext, isActive and Job.isActive.


val CoroutineContext.isActive: Boolean

Returns true when the Job of the coroutine in this context is still active (has not completed and was not cancelled yet).

Check this property in long-running computation loops to support cancellation when CoroutineScope.isActive is not available:

while (coroutineContext.isActive) {
// do some computation
}

The coroutineContext.isActive expression is a shortcut for coroutineContext[Job]?.isActive == true. See Job.isActive.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/is-present.html b/kotlinx-coroutines-core/kotlinx.coroutines/is-present.html index 0bef2a5599..9ed598138d 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/is-present.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/is-present.html @@ -1,72 +1 @@ - - - - - isPresent - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

isPresent

-
-
-
-
inline suspend fun ThreadLocal<*>.isPresent(): Boolean

Return true when current thread local is present in the coroutine context, false otherwise. Thread local can be present in the context only if it was added via asContextElement to the context.

Example of usage:

suspend fun processRequest() {
if (traceCurrentRequestThreadLocal.isPresent()) { // Probabilistic tracing
// Do some heavy-weight tracing
}
// Process request regularly
}
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/job.html b/kotlinx-coroutines-core/kotlinx.coroutines/job.html index 4c7d4be1b9..58d6ae029d 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/job.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/job.html @@ -1,72 +1 @@ - - - - - job - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

job

-
-
-
-
val CoroutineContext.job: Job

Retrieves the current Job instance from the given CoroutineContext or throws IllegalStateException if no job is present in the context.

This method is a short-cut for coroutineContext[Job]!! and should be used only when it is known in advance that the context does have instance of the job in it.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/join-all.html b/kotlinx-coroutines-core/kotlinx.coroutines/join-all.html index 3041c277ea..aa3af34fb7 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/join-all.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/join-all.html @@ -1,83 +1 @@ - - - - - joinAll - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

joinAll

-
-
-
-
suspend fun joinAll(vararg jobs: Job)

Suspends current coroutine until all given jobs are complete. This method is semantically equivalent to joining all given jobs one by one with jobs.forEach { it.join() }.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this suspending function is waiting, this function immediately resumes with CancellationException. There is a prompt cancellation guarantee. If the job was cancelled while this function was suspended, it will not resume successfully. See suspendCancellableCoroutine documentation for low-level details.


suspend fun Collection<Job>.joinAll()

Suspends current coroutine until all given jobs are complete. This method is semantically equivalent to joining all given jobs one by one with forEach { it.join() }.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this suspending function is waiting, this function immediately resumes with CancellationException. There is a prompt cancellation guarantee. If the job was cancelled while this function was suspended, it will not resume successfully. See suspendCancellableCoroutine documentation for low-level details.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/launch.html b/kotlinx-coroutines-core/kotlinx.coroutines/launch.html index 4fdf0d6c4c..db8e16a488 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/launch.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/launch.html @@ -1,72 +1 @@ - - - - - launch - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

launch

-
-
-
-
fun CoroutineScope.launch(    context: CoroutineContext = EmptyCoroutineContext,     start: CoroutineStart = CoroutineStart.DEFAULT,     block: suspend CoroutineScope.() -> Unit): Job

Launches a new coroutine without blocking the current thread and returns a reference to the coroutine as a Job. The coroutine is cancelled when the resulting job is cancelled.

The coroutine context is inherited from a CoroutineScope. Additional context elements can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. The parent job is inherited from a CoroutineScope as well, but it can also be overridden with a corresponding context element.

By default, the coroutine is immediately scheduled for execution. Other start options can be specified via start parameter. See CoroutineStart for details. An optional start parameter can be set to CoroutineStart.LAZY to start coroutine lazily. In this case, the coroutine Job is created in new state. It can be explicitly started with start function and will be started implicitly on the first invocation of join.

Uncaught exceptions in this coroutine cancel the parent job in the context by default (unless CoroutineExceptionHandler is explicitly specified), which means that when launch is used with the context of another coroutine, then any uncaught exception leads to the cancellation of the parent coroutine.

See newCoroutineContext for a description of debugging facilities that are available for a newly created coroutine.

Parameters

context

additional to CoroutineScope.coroutineContext context of the coroutine.

start

coroutine start option. The default value is CoroutineStart.DEFAULT.

block

the coroutine code which will be invoked in the context of the provided scope.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/new-coroutine-context.html b/kotlinx-coroutines-core/kotlinx.coroutines/new-coroutine-context.html index a022e1f36a..5d46f511dc 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/new-coroutine-context.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/new-coroutine-context.html @@ -1,108 +1 @@ - - - - - newCoroutineContext - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

newCoroutineContext

-
-
-
-
expect fun CoroutineScope.newCoroutineContext(context: CoroutineContext): CoroutineContext

Creates a context for a new coroutine. It installs Dispatchers.Default when no other dispatcher or ContinuationInterceptor is specified and adds optional support for debugging facilities (when turned on) and copyable-thread-local facilities on JVM.

actual fun CoroutineScope.newCoroutineContext(context: CoroutineContext): CoroutineContext

Creates a context for a new coroutine. It installs Dispatchers.Default when no other dispatcher or ContinuationInterceptor is specified and adds optional support for debugging facilities (when turned on) and copyable-thread-local facilities on JVM. See DEBUG_PROPERTY_NAME for description of debugging facilities on JVM.

actual fun CoroutineScope.newCoroutineContext(context: CoroutineContext): CoroutineContext
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/new-fixed-thread-pool-context.html b/kotlinx-coroutines-core/kotlinx.coroutines/new-fixed-thread-pool-context.html index f206c91926..7738e29990 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/new-fixed-thread-pool-context.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/new-fixed-thread-pool-context.html @@ -1,85 +1 @@ - - - - - newFixedThreadPoolContext - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

newFixedThreadPoolContext

-
-
-
-
expect fun newFixedThreadPoolContext(nThreads: Int, name: String): CloseableCoroutineDispatcher
actual fun newFixedThreadPoolContext(nThreads: Int, name: String): CloseableCoroutineDispatcher

Creates a coroutine execution context with the fixed-size thread-pool and built-in yield support. NOTE: The resulting ExecutorCoroutineDispatcher owns native resources (its threads). Resources are reclaimed by ExecutorCoroutineDispatcher.close.

If the resulting dispatcher is closed and attempt to submit a continuation task is made, then the Job of the affected task is cancelled and the task is submitted to the Dispatchers.IO, so that the affected coroutine can cleanup its resources and promptly complete.

This is a delicate API. The result of this method is a closeable resource with the associated native resources (threads). It should not be allocated in place, should be closed at the end of its lifecycle, and has non-trivial memory and CPU footprint. If you do not need a separate thread-pool, but only have to limit effective parallelism of the dispatcher, it is recommended to use CoroutineDispatcher.limitedParallelism instead.

If you need a completely separate thread-pool with scheduling policy that is based on the standard JDK executors, use the following expression: Executors.newFixedThreadPool().asCoroutineDispatcher(). See Executor.asCoroutineDispatcher for details.

Parameters

nThreads

the number of threads.

name

the base name of the created threads.

actual fun newFixedThreadPoolContext(nThreads: Int, name: String): CloseableCoroutineDispatcher
-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/new-single-thread-context.html b/kotlinx-coroutines-core/kotlinx.coroutines/new-single-thread-context.html index 686f010cd7..3ac49b8d3f 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/new-single-thread-context.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/new-single-thread-context.html @@ -1,85 +1 @@ - - - - - newSingleThreadContext - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

newSingleThreadContext

-
-
-
-

Creates a coroutine execution context using a single thread with built-in yield support. NOTE: The resulting ExecutorCoroutineDispatcher owns native resources (its thread). Resources are reclaimed by ExecutorCoroutineDispatcher.close.

If the resulting dispatcher is closed and attempt to submit a continuation task is made, then the Job of the affected task is cancelled and the task is submitted to the Dispatchers.IO, so that the affected coroutine can cleanup its resources and promptly complete.

This is a delicate API. The result of this method is a closeable resource with the associated native resources (threads). It should not be allocated in place, should be closed at the end of its lifecycle, and has non-trivial memory and CPU footprint. If you do not need a separate thread-pool, but only have to limit effective parallelism of the dispatcher, it is recommended to use CoroutineDispatcher.limitedParallelism instead.

If you need a completely separate thread-pool with scheduling policy that is based on the standard JDK executors, use the following expression: Executors.newSingleThreadExecutor().asCoroutineDispatcher(). See Executor.asCoroutineDispatcher for details.

Parameters

name

the base name of the created thread.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/plus.html b/kotlinx-coroutines-core/kotlinx.coroutines/plus.html index a2a7be62a8..17b6d89422 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/plus.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/plus.html @@ -1,72 +1 @@ - - - - - plus - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

plus

-
-
-
-
operator fun CoroutineScope.plus(context: CoroutineContext): CoroutineScope

Adds the specified coroutine context to this scope, overriding existing elements in the current scope's context with the corresponding keys.

This is a shorthand for CoroutineScope(thisScope + context).

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/promise.html b/kotlinx-coroutines-core/kotlinx.coroutines/promise.html index 29046cbe02..ddc79597c9 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/promise.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/promise.html @@ -1,72 +1 @@ - - - - - promise - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

promise

-
-
-
-
fun <T> CoroutineScope.promise(    context: CoroutineContext = EmptyCoroutineContext,     start: CoroutineStart = CoroutineStart.DEFAULT,     block: suspend CoroutineScope.() -> T): Promise<T>

Starts new coroutine and returns its result as an implementation of Promise.

Coroutine context is inherited from a CoroutineScope, additional context elements can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. The parent job is inherited from a CoroutineScope as well, but it can also be overridden with corresponding context element.

By default, the coroutine is immediately scheduled for execution. Other options can be specified via start parameter. See CoroutineStart for details.

Parameters

context

additional to CoroutineScope.coroutineContext context of the coroutine.

start

coroutine start option. The default value is CoroutineStart.DEFAULT.

block

the coroutine code.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/run-blocking.html b/kotlinx-coroutines-core/kotlinx.coroutines/run-blocking.html index 5b26312d4a..11a5e46e6c 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/run-blocking.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/run-blocking.html @@ -1,85 +1 @@ - - - - - runBlocking - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

runBlocking

-
-
-
-
expect fun <T> runBlocking(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): T

Runs a new coroutine and blocks the current thread until its completion. This function should not be used from a coroutine. It is designed to bridge regular blocking code to libraries that are written in suspending style, to be used in main functions and in tests.

actual fun <T> runBlocking(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): T

Runs a new coroutine and blocks the current thread interruptibly until its completion. This function should not be used from a coroutine. It is designed to bridge regular blocking code to libraries that are written in suspending style, to be used in main functions and in tests.

The default CoroutineDispatcher for this builder is an internal implementation of event loop that processes continuations in this blocked thread until the completion of this coroutine. See CoroutineDispatcher for the other implementations that are provided by kotlinx.coroutines.

When CoroutineDispatcher is explicitly specified in the context, then the new coroutine runs in the context of the specified dispatcher while the current thread is blocked. If the specified dispatcher is an event loop of another runBlocking, then this invocation uses the outer event loop.

If this blocked thread is interrupted (see Thread.interrupt), then the coroutine job is cancelled and this runBlocking invocation throws InterruptedException.

See newCoroutineContext for a description of debugging facilities that are available for a newly created coroutine.

Parameters

context

the context of the coroutine. The default value is an event loop on the current thread.

block

the coroutine code.

actual fun <T> runBlocking(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): T

Runs new coroutine and blocks current thread interruptibly until its completion. This function should not be used from coroutine. It is designed to bridge regular blocking code to libraries that are written in suspending style, to be used in main functions and in tests.

The default CoroutineDispatcher for this builder in an implementation of EventLoop that processes continuations in this blocked thread until the completion of this coroutine. See CoroutineDispatcher for the other implementations that are provided by kotlinx.coroutines.

When CoroutineDispatcher is explicitly specified in the context, then the new coroutine runs in the context of the specified dispatcher while the current thread is blocked. If the specified dispatcher implements EventLoop interface and this runBlocking invocation is performed from inside of the this event loop's thread, then this event loop is processed using its processNextEvent method until coroutine completes.

If this blocked thread is interrupted (see Thread.interrupt), then the coroutine job is cancelled and this runBlocking invocation throws InterruptedException.

See newCoroutineContext for a description of debugging facilities that are available for newly created coroutine.

Parameters

context

context of the coroutine. The default value is an implementation of EventLoop.

block

the coroutine code.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/run-interruptible.html b/kotlinx-coroutines-core/kotlinx.coroutines/run-interruptible.html index 98b9348578..21649073ca 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/run-interruptible.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/run-interruptible.html @@ -1,72 +1 @@ - - - - - runInterruptible - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

runInterruptible

-
-
-
-
suspend fun <T> runInterruptible(context: CoroutineContext = EmptyCoroutineContext, block: () -> T): T

Calls the specified block with a given coroutine context in an interruptible manner. The blocking code block will be interrupted and this function will throw CancellationException if the coroutine is cancelled.

Example:

withTimeout(500L) {            // Cancels coroutine on timeout
runInterruptible { // Throws CancellationException if interrupted
doSomethingBlocking() // Interrupted on coroutines cancellation
}
}

There is an optional context parameter to this function working just like withContext. It enables single-call conversion of interruptible Java methods into suspending functions. With one call here we are moving the call to Dispatchers.IO and supporting interruption:

suspend fun <T> BlockingQueue<T>.awaitTake(): T =
runInterruptible(Dispatchers.IO) { queue.take() }

runInterruptible uses withContext as an underlying mechanism for switching context, meaning that the supplied block is invoked in an undispatched manner directly by the caller if CoroutineDispatcher from the current coroutineContext is the same as the one supplied in context.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/supervisor-scope.html b/kotlinx-coroutines-core/kotlinx.coroutines/supervisor-scope.html index ea191ab798..1b6d93596c 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/supervisor-scope.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/supervisor-scope.html @@ -1,72 +1 @@ - - - - - supervisorScope - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

supervisorScope

-
-
-
-
suspend fun <R> supervisorScope(block: suspend CoroutineScope.() -> R): R

Creates a CoroutineScope with SupervisorJob and calls the specified suspend block with this scope. The provided scope inherits its coroutineContext from the outer scope, but overrides context's Job with SupervisorJob. This function returns as soon as the given block and all its child coroutines are completed.

Unlike coroutineScope, a failure of a child does not cause this scope to fail and does not affect its other children, so a custom policy for handling failures of its children can be implemented. See SupervisorJob for additional details. A failure of the scope itself (exception thrown in the block or external cancellation) fails the scope with all its children, but does not cancel parent job.

The method may throw a CancellationException if the current job was cancelled externally, or rethrow an exception thrown by the given block.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/suspend-cancellable-coroutine.html b/kotlinx-coroutines-core/kotlinx.coroutines/suspend-cancellable-coroutine.html index b44db15326..264b8af039 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/suspend-cancellable-coroutine.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/suspend-cancellable-coroutine.html @@ -1,72 +1 @@ - - - - - suspendCancellableCoroutine - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

suspendCancellableCoroutine

-
-
-
-
inline suspend fun <T> suspendCancellableCoroutine(crossinline block: (CancellableContinuation<T>) -> Unit): T

Suspends the coroutine like suspendCoroutine, but providing a CancellableContinuation to the block. This function throws a CancellationException if the Job of the coroutine is cancelled or completed while it is suspended.

A typical use of this function is to suspend a coroutine while waiting for a result from a single-shot callback API and to return the result to the caller. For multi-shot callback APIs see callbackFlow.

suspend fun awaitCallback(): T = suspendCancellableCoroutine { continuation ->
val callback = object : Callback { // Implementation of some callback interface
override fun onCompleted(value: T) {
// Resume coroutine with a value provided by the callback
continuation.resume(value)
}
override fun onApiError(cause: Throwable) {
// Resume coroutine with an exception provided by the callback
continuation.resumeWithException(cause)
}
}
// Register callback with an API
api.register(callback)
// Remove callback on cancellation
continuation.invokeOnCancellation { api.unregister(callback) }
// At this point the coroutine is suspended by suspendCancellableCoroutine until callback fires
}

The callback register/unregister methods provided by an external API must be thread-safe, because invokeOnCancellation block can be called at any time due to asynchronous nature of cancellation, even concurrently with the call of the callback.

Prompt cancellation guarantee

This function provides prompt cancellation guarantee. If the Job of the current coroutine was cancelled while this function was suspended it will not resume successfully.

The cancellation of the coroutine's job is generally asynchronous with respect to the suspended coroutine. The suspended coroutine is resumed with the call it to its Continuation.resumeWith member function or to resume extension function. However, when coroutine is resumed, it does not immediately start executing, but is passed to its CoroutineDispatcher to schedule its execution when dispatcher's resources become available for execution. The job's cancellation can happen both before, after, and concurrently with the call to resume. In any case, prompt cancellation guarantees that the the coroutine will not resume its code successfully.

If the coroutine was resumed with an exception (for example, using Continuation.resumeWithException extension function) and cancelled, then the resulting exception of the suspendCancellableCoroutine function is determined by whichever action (exceptional resume or cancellation) that happened first.

Returning resources from a suspended coroutine

As a result of a prompt cancellation guarantee, when a closeable resource (like open file or a handle to another native resource) is returned from a suspended coroutine as a value it can be lost when the coroutine is cancelled. In order to ensure that the resource can be properly closed in this case, the CancellableContinuation interface provides two functions.

  • invokeOnCancellation installs a handler that is called whenever a suspend coroutine is being cancelled. In addition to the example at the beginning, it can be used to ensure that a resource that was opened before the call to suspendCancellableCoroutine or in its body is closed in case of cancellation.

suspendCancellableCoroutine { continuation ->
val resource = openResource() // Opens some resource
continuation.invokeOnCancellation {
resource.close() // Ensures the resource is closed on cancellation
}
// ...
}
  • resume(value) { ... } method on a CancellableContinuation takes an optional onCancellation block. It can be used when resuming with a resource that must be closed by the code that called the corresponding suspending function.

suspendCancellableCoroutine { continuation ->
val callback = object : Callback { // Implementation of some callback interface
// A callback provides a reference to some closeable resource
override fun onCompleted(resource: T) {
// Resume coroutine with a value provided by the callback and ensure the resource is closed in case
// when the coroutine is cancelled before the caller gets a reference to the resource.
continuation.resume(resource) {
resource.close() // Close the resource on cancellation
}
}
// ...
}

Implementation details and custom continuation interceptors

The prompt cancellation guarantee is the result of a coordinated implementation inside suspendCancellableCoroutine function and the CoroutineDispatcher class. The coroutine dispatcher checks for the status of the Job immediately before continuing its normal execution and aborts this normal execution, calling all the corresponding cancellation handlers, if the job was cancelled.

If a custom implementation of ContinuationInterceptor is used in a coroutine's context that does not extend CoroutineDispatcher class, then there is no prompt cancellation guarantee. A custom continuation interceptor can resume execution of a previously suspended coroutine even if its job was already cancelled.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/with-context.html b/kotlinx-coroutines-core/kotlinx.coroutines/with-context.html index ddb0cc23b4..75664a4170 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/with-context.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/with-context.html @@ -1,72 +1 @@ - - - - - withContext - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

withContext

-
-
-
-
suspend fun <T> withContext(context: CoroutineContext, block: suspend CoroutineScope.() -> T): T

Calls the specified suspending block with a given coroutine context, suspends until it completes, and returns the result.

The resulting context for the block is derived by merging the current coroutineContext with the specified context using coroutineContext + context (see CoroutineContext.plus). This suspending function is cancellable. It immediately checks for cancellation of the resulting context and throws CancellationException if it is not active.

Calls to withContext whose context argument provides a CoroutineDispatcher that is different from the current one, by necessity, perform additional dispatches: the block can not be executed immediately and needs to be dispatched for execution on the passed CoroutineDispatcher, and then when the block completes, the execution has to shift back to the original dispatcher.

Note that the result of withContext invocation is dispatched into the original context in a cancellable way with a prompt cancellation guarantee, which means that if the original coroutineContext in which withContext was invoked is cancelled by the time its dispatcher starts to execute the code, it discards the result of withContext and throws CancellationException.

The cancellation behaviour described above is enabled if and only if the dispatcher is being changed. For example, when using withContext(NonCancellable) { ... } there is no change in dispatcher and this call will not be cancelled neither on entry to the block inside withContext nor on exit from it.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/with-timeout-or-null.html b/kotlinx-coroutines-core/kotlinx.coroutines/with-timeout-or-null.html index 709c8106b8..fe074c5ba1 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/with-timeout-or-null.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/with-timeout-or-null.html @@ -1,83 +1 @@ - - - - - withTimeoutOrNull - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

withTimeoutOrNull

-
-
-
-
suspend fun <T> withTimeoutOrNull(timeMillis: Long, block: suspend CoroutineScope.() -> T): T?

Runs a given suspending block of code inside a coroutine with a specified timeout and returns null if this timeout was exceeded.

The code that is executing inside the block is cancelled on timeout and the active or next invocation of cancellable suspending function inside the block throws a TimeoutCancellationException.

The sibling function that throws an exception on timeout is withTimeout. Note that the timeout action can be specified for a select invocation with onTimeout clause.

The timeout event is asynchronous with respect to the code running in the block and may happen at any time, even right before the return from inside of the timeout block. Keep this in mind if you open or acquire some resource inside the block that needs closing or release outside of the block. See the Asynchronous timeout and resources[https://kotlinlang.org/docs/reference/coroutines/cancellation-and-timeouts.html#asynchronous-timeout-and-resources] section of the coroutines guide for details.

Implementation note: how the time is tracked exactly is an implementation detail of the context's CoroutineDispatcher.

Parameters

timeMillis

timeout time in milliseconds.


suspend fun <T> withTimeoutOrNull(timeout: Duration, block: suspend CoroutineScope.() -> T): T?

Runs a given suspending block of code inside a coroutine with the specified timeout and returns null if this timeout was exceeded.

The code that is executing inside the block is cancelled on timeout and the active or next invocation of cancellable suspending function inside the block throws a TimeoutCancellationException.

The sibling function that throws an exception on timeout is withTimeout. Note that the timeout action can be specified for a select invocation with onTimeout clause.

The timeout event is asynchronous with respect to the code running in the block and may happen at any time, even right before the return from inside of the timeout block. Keep this in mind if you open or acquire some resource inside the block that needs closing or release outside of the block. See the Asynchronous timeout and resources[https://kotlinlang.org/docs/reference/coroutines/cancellation-and-timeouts.html#asynchronous-timeout-and-resources] section of the coroutines guide for details.

Implementation note: how the time is tracked exactly is an implementation detail of the context's CoroutineDispatcher.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/with-timeout.html b/kotlinx-coroutines-core/kotlinx.coroutines/with-timeout.html index 018a2bb10c..feae0e55ed 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/with-timeout.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/with-timeout.html @@ -1,83 +1 @@ - - - - - withTimeout - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

withTimeout

-
-
-
-
suspend fun <T> withTimeout(timeMillis: Long, block: suspend CoroutineScope.() -> T): T

Runs a given suspending block of code inside a coroutine with a specified timeout and throws a TimeoutCancellationException if the timeout was exceeded.

The code that is executing inside the block is cancelled on timeout and the active or next invocation of the cancellable suspending function inside the block throws a TimeoutCancellationException.

The sibling function that does not throw an exception on timeout is withTimeoutOrNull. Note that the timeout action can be specified for a select invocation with onTimeout clause.

The timeout event is asynchronous with respect to the code running in the block and may happen at any time, even right before the return from inside of the timeout block. Keep this in mind if you open or acquire some resource inside the block that needs closing or release outside of the block. See the Asynchronous timeout and resources[https://kotlinlang.org/docs/reference/coroutines/cancellation-and-timeouts.html#asynchronous-timeout-and-resources] section of the coroutines guide for details.

Implementation note: how the time is tracked exactly is an implementation detail of the context's CoroutineDispatcher.

Parameters

timeMillis

timeout time in milliseconds.


suspend fun <T> withTimeout(timeout: Duration, block: suspend CoroutineScope.() -> T): T

Runs a given suspending block of code inside a coroutine with the specified timeout and throws a TimeoutCancellationException if the timeout was exceeded.

The code that is executing inside the block is cancelled on timeout and the active or next invocation of the cancellable suspending function inside the block throws a TimeoutCancellationException.

The sibling function that does not throw an exception on timeout is withTimeoutOrNull. Note that the timeout action can be specified for a select invocation with onTimeout clause.

The timeout event is asynchronous with respect to the code running in the block and may happen at any time, even right before the return from inside of the timeout block. Keep this in mind if you open or acquire some resource inside the block that needs closing or release outside of the block. See the Asynchronous timeout and resources[https://kotlinlang.org/docs/reference/coroutines/cancellation-and-timeouts.html#asynchronous-timeout-and-resources] section of the coroutines guide for details.

Implementation note: how the time is tracked exactly is an implementation detail of the context's CoroutineDispatcher.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/kotlinx.coroutines/yield.html b/kotlinx-coroutines-core/kotlinx.coroutines/yield.html index 2e8d3da8d8..cc6685aeee 100644 --- a/kotlinx-coroutines-core/kotlinx.coroutines/yield.html +++ b/kotlinx-coroutines-core/kotlinx.coroutines/yield.html @@ -1,72 +1 @@ - - - - - yield - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

yield

-
-
-
-
suspend fun yield()

Yields the thread (or thread pool) of the current coroutine dispatcher to other coroutines on the same dispatcher to run if possible.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed when this suspending function is invoked or while this function is waiting for dispatch, it resumes with a CancellationException. There is a prompt cancellation guarantee. If the job was cancelled while this function was suspended, it will not resume successfully. See suspendCancellableCoroutine documentation for low-level details.

Note: This function always checks for cancellation even when it does not suspend.

Implementation details

If the coroutine dispatcher is Unconfined, this functions suspends only when there are other unconfined coroutines working and forming an event-loop. For other dispatchers, this function calls CoroutineDispatcher.dispatch and always suspends to be resumed later regardless of the result of CoroutineDispatcher.isDispatchNeeded. If there is no CoroutineDispatcher in the context, it does not suspend.

-

Sources

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-core/navigation.html b/kotlinx-coroutines-core/navigation.html deleted file mode 100644 index be03fe14df..0000000000 --- a/kotlinx-coroutines-core/navigation.html +++ /dev/null @@ -1,2047 +0,0 @@ -
- -
- -
- - - -
- -
-
- -
-
- -
-
-
- async() -
-
-
-
- await() -
-
-
- -
- - -
-
- cancel() -
-
-
- -
- - - - - - - - -
- -
-
- -
- - - - - -
- -
-
- -
- - -
- -
-
- ATOMIC -
-
-
-
- DEFAULT -
-
-
-
- LAZY -
-
-
- -
-
- - - - - -
-
- Deferred -
-
-
-
- delay() -
-
- -
- -
- -
- -
-
- -
- - -
- -
-
- -
- - -
-
- invoke() -
-
- -
-
- isActive -
-
-
- -
-
-
- Job -
-
-
-
- job -
-
-
-
- Job() -
-
-
-
- joinAll() -
-
-
-
- launch() -
-
- -
- -
- - - -
- -
- -
-
- plus() -
-
-
-
- promise() -
-
-
- -
- -
-
- Runnable -
-
-
- -
-
- -
- - - - -
- -
-
- -
- -
-
- yield() -
-
-
-
- -
-
- actor() -
-
-
- -
-
- -
-
- -
- - -
- -
- -
-
- -
-
-
- SUSPEND -
-
-
-
-
- Channel -
-
-
-
- Channel() -
-
-
- -
-
- -
- - - -
-
- consume() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- produce() -
-
-
- -
-
- -
-
- -
-
-
- ticker() -
-
-
- -
- -
-
- -
-
-
-
- toList() -
-
- -
-
- -
- -
-
-
- asFlow() -
-
-
- -
-
- -
-
-
- buffer() -
-
-
- -
-
- -
-
-
- catch() -
-
-
- -
-
-
- collect() -
-
- -
- -
-
-
- combine() -
-
- -
- -
-
- -
-
-
- count() -
-
-
- -
- - - - -
-
- drop() -
-
-
- -
-
-
- emitAll() -
-
-
- -
-
-
- filter() -
-
- -
- -
-
- -
-
-
- first() -
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
- Flow -
-
-
-
- flow() -
-
-
- -
-
-
- flowOf() -
-
-
-
- flowOn() -
-
-
-
- fold() -
-
-
- -
-
-
- last() -
-
-
- -
-
- -
-
-
- map() -
-
-
- -
-
- -
-
-
- merge() -
-
- - - - -
- -
-
-
- onEach() -
-
-
-
- onEmpty() -
-
-
-
- onStart() -
-
- -
- -
-
- -
-
-
- reduce() -
-
-
-
- retry() -
-
-
- -
-
- -
-
- -
-
-
- sample() -
-
-
-
- scan() -
-
-
- -
-
-
- shareIn() -
-
-
- -
-
- START -
-
-
-
- STOP -
-
- -
-
- -
-
-
- single() -
-
-
- -
-
-
- StateFlow -
-
-
-
- stateIn() -
-
-
-
- take() -
-
-
- -
-
- -
-
-
- toList() -
-
-
-
- toSet() -
-
-
- -
- - -
-
- update() -
-
-
- -
- -
- -
-
-
- zip() -
-
-
- -
- -
- -
-
-
- select() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- -
-
- Mutex -
-
-
-
- Mutex() -
-
-
-
- Semaphore -
-
-
- -
-
- -
-
- -
-
-
- -
- -
- -
- -
- -
-
- await() -
-
-
-
- future() -
-
-
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
-
- JavaFx -
-
- -
-
-
- -
- - -
- -
-
-
- await() -
-
-
-
- future() -
-
-
- -
- -
- -
-
-
- delay() -
-
-
- -
-
-
- sample() -
-
-
- -
- -
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
- -
-
-
- -
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
-
- publish() -
-
-
-
- -
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
-
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
- - - -
diff --git a/kotlinx-coroutines-debug/index.html b/kotlinx-coroutines-debug/index.html index 63096f4f0c..0977dbc071 100644 --- a/kotlinx-coroutines-debug/index.html +++ b/kotlinx-coroutines-debug/index.html @@ -1,156 +1 @@ - - - - - kotlinx-coroutines-debug - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

kotlinx-coroutines-debug

-

Debugging facilities for kotlinx.coroutines on JVM.

Overview

This module provides a debug JVM agent that allows to track and trace existing coroutines. The main entry point to debug facilities is DebugProbes API. Call to DebugProbes.install installs debug agent via ByteBuddy and starts spying on coroutines when they are created, suspended and resumed.

After that, you can use DebugProbes.dumpCoroutines to print all active (suspended or running) coroutines, including their state, creation and suspension stacktraces. Additionally, it is possible to process the list of such coroutines via DebugProbes.dumpCoroutinesInfo or dump isolated parts of coroutines hierarchy referenced by a Job or CoroutineScope instances using DebugProbes.printJob and DebugProbes.printScope respectively.

This module also provides an automatic BlockHound integration that detects when a blocking operation was called in a coroutine context that prohibits it. In order to use it, please follow the BlockHound quick start guide.

Using in your project

Add kotlinx-coroutines-debug to your project test dependencies:

dependencies {
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-debug:1.4.0'
}

Using in unit tests

For JUnit4 debug module provides special test rule, CoroutinesTimeout, for installing debug probes and to dump coroutines on timeout to simplify tests debugging.

Its usage is better demonstrated by the example (runnable code is test/TestRuleExample.kt):

class TestRuleExample {
@get:Rule
public val timeout = CoroutinesTimeout.seconds(1)

private suspend fun someFunctionDeepInTheStack() {
withContext(Dispatchers.IO) {
delay(Long.MAX_VALUE) // Hang method
}
}

@Test
fun hangingTest() = runBlocking {
val job = launch {
someFunctionDeepInTheStack()
}
job.join() // Join will hang
}
}

After 1 second, test will fail with TestTimeoutException and all coroutines (runBlocking and launch) and their stacktraces will be dumped to the console.

Using as JVM agent

Debug module can also be used as a standalone JVM agent to enable debug probes on the application startup. You can run your application with an additional argument: -javaagent:kotlinx-coroutines-debug-1.6.3.jar. Additionally, on Linux and Mac OS X you can use kill -5 $pid command in order to force your application to print all alive coroutines. When used as Java agent, "kotlinx.coroutines.debug.enable.creation.stack.trace" system property can be used to control DebugProbes.enableCreationStackTraces along with agent startup.

Using in production environment

It is possible to run an application in production environments with debug probes in order to monitor its state and improve its observability. For that, it is strongly recommended to switch off DebugProbes.enableCreationStackTraces property to significantly reduce the overhead of debug probes and make it insignificant. With creation stack-traces disabled, the typical overhead of enabled debug probes is a single-digit percentage of the total application throughput.

Example of usage

Capabilities of this module can be demonstrated by the following example (runnable code is test/Example.kt):

suspend fun computeValue(): String = coroutineScope {
val one = async { computeOne() }
val two = async { computeTwo() }
combineResults(one, two)
}

suspend fun combineResults(one: Deferred<String>, two: Deferred<String>): String =
one.await() + two.await()

suspend fun computeOne(): String {
delay(5000)
return "4"
}

suspend fun computeTwo(): String {
delay(5000)
return "2"
}

fun main() = runBlocking {
DebugProbes.install()
val deferred = async { computeValue() }
// Delay for some time
delay(1000)
// Dump running coroutines
DebugProbes.dumpCoroutines()
println("\nDumping only deferred")
DebugProbes.printJob(deferred)
}

Printed result will be:

Coroutines dump 2018/11/12 21:44:02

Coroutine "coroutine#2":DeferredCoroutine{Active}@289d1c02, state: SUSPENDED
at kotlinx.coroutines.DeferredCoroutine.await$suspendImpl(Builders.common.kt:99)
at ExampleKt.combineResults(Example.kt:11)
at ExampleKt$computeValue$2.invokeSuspend(Example.kt:7)
at ExampleKt$main$1$deferred$1.invokeSuspend(Example.kt:25)
(Coroutine creation stacktrace)
at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt.createCoroutineUnintercepted(IntrinsicsJvm.kt:116)
at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:25)
at kotlinx.coroutines.BuildersKt.async$default(Unknown Source)
at ExampleKt$main$1.invokeSuspend(Example.kt:25)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:233)
at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
at ExampleKt.main(Example.kt:23)
at ExampleKt.main(Example.kt)

... More coroutines here ...

Dumping only deferred
"coroutine#2":DeferredCoroutine{Active}, continuation is SUSPENDED at line kotlinx.coroutines.DeferredCoroutine.await$suspendImpl(Builders.common.kt:99)
"coroutine#3":DeferredCoroutine{Active}, continuation is SUSPENDED at line ExampleKt.computeOne(Example.kt:14)
"coroutine#4":DeferredCoroutine{Active}, continuation is SUSPENDED at line ExampleKt.computeTwo(Example.kt:19)

Status of the API

API is experimental, and it is not guaranteed it won't be changed (while it is marked as @ExperimentalCoroutinesApi). Like the rest of experimental API, DebugProbes is carefully designed, tested and ready to use in both test and production environments. It is marked as experimental to leave us the room to enrich the output data in a potentially backwards incompatible manner to further improve diagnostics and debugging experience.

The output format of DebugProbes can be changed in the future and it is not recommended to rely on the string representation of the dump programmatically.

Debug agent and Android

Android runtime does not support Instrument API necessary for kotlinx-coroutines-debug to function, triggering java.lang.NoClassDefFoundError: Failed resolution of: Ljava/lang/management/ManagementFactory;, and it is not possible to use coroutine debugger along with Android emulator.

Build failures due to duplicate resource files

Building an Android project that depends on kotlinx-coroutines-debug (usually introduced by being a transitive dependency of kotlinx-coroutines-test) may fail with DuplicateRelativeFileException for META-INF/AL2.0, META-INF/LGPL2.1, or win32-x86/attach_hotspot_windows.dll when trying to merge the Android resource.

The problem is that Android merges the resources of all its dependencies into a single directory and complains about conflicts, but:

  • kotlinx-coroutines-debug transitively depends on JNA and JNA-platform, both of which include license files in their META-INF directories. Trying to merge these files leads to conflicts, which means that any Android project that depends on JNA and JNA-platform will experience build failures.

  • Additionally, kotlinx-coroutines-debug embeds byte-buddy-agent and byte-buddy, along with their resource files. Then, if the project separately depends on byte-buddy, merging the resources of kotlinx-coroutines-debug with ones from byte-buddy and byte-buddy-agent will lead to conflicts as the resource files are duplicated.

One possible workaround for these issues is to add the following to the android block in your gradle file for the application subproject:

     packagingOptions {
// for JNA and JNA-platform
exclude "META-INF/AL2.0"
exclude "META-INF/LGPL2.1"
// for byte-buddy
exclude "META-INF/licenses/ASM"
pickFirst "win32-x86-64/attach_hotspot_windows.dll"
pickFirst "win32-x86/attach_hotspot_windows.dll"
}

This will cause the resource merge algorithm to exclude the problematic license files altogether and only leave a single copy of the files needed for byte-buddy-agent to work.

Alternatively, avoid depending on kotlinx-coroutines-debug. In particular, if the only reason why this library a dependency of your project is that kotlinx-coroutines-test in turn depends on it, you may change your dependency on kotlinx.coroutines.test to exclude kotlinx-coroutines-debug. For example, you could replace

androidTestImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version")

with

androidTestImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version") {
exclude group: "org.jetbrains.kotlinx", module: "kotlinx-coroutines-debug"
}
-
-

Packages

-
-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit4/-coroutines-timeout/-companion/index.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit4/-coroutines-timeout/-companion/index.html index 6bf28afe57..c223a9bcc5 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit4/-coroutines-timeout/-companion/index.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit4/-coroutines-timeout/-companion/index.html @@ -1,76 +1 @@ - - - - - Companion - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Companion

-
object Companion
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
fun seconds(    seconds: Int,     cancelOnTimeout: Boolean = false,     enableCoroutineCreationStackTraces: Boolean = true): CoroutinesTimeout
fun seconds(    seconds: Long,     cancelOnTimeout: Boolean = false,     enableCoroutineCreationStackTraces: Boolean = true): CoroutinesTimeout

Creates CoroutinesTimeout rule with the given timeout in seconds.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit4/-coroutines-timeout/-companion/seconds.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit4/-coroutines-timeout/-companion/seconds.html index e625f6d94e..5d67db65a5 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit4/-coroutines-timeout/-companion/seconds.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit4/-coroutines-timeout/-companion/seconds.html @@ -1,54 +1 @@ - - - - - seconds - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

seconds

-
-
fun seconds(    seconds: Int,     cancelOnTimeout: Boolean = false,     enableCoroutineCreationStackTraces: Boolean = true): CoroutinesTimeout
fun seconds(    seconds: Long,     cancelOnTimeout: Boolean = false,     enableCoroutineCreationStackTraces: Boolean = true): CoroutinesTimeout

Creates CoroutinesTimeout rule with the given timeout in seconds.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit4/-coroutines-timeout/-coroutines-timeout.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit4/-coroutines-timeout/-coroutines-timeout.html index ecaab4cbd8..6bc83f3e91 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit4/-coroutines-timeout/-coroutines-timeout.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit4/-coroutines-timeout/-coroutines-timeout.html @@ -1,54 +1 @@ - - - - - CoroutinesTimeout - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CoroutinesTimeout

-
-
fun CoroutinesTimeout(testTimeoutMs: Long, cancelOnTimeout: Boolean = false)
fun CoroutinesTimeout(    testTimeoutMs: Long,     cancelOnTimeout: Boolean = false,     enableCoroutineCreationStackTraces: Boolean = true)
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit4/-coroutines-timeout/index.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit4/-coroutines-timeout/index.html index abfd55431f..c14b271cf2 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit4/-coroutines-timeout/index.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit4/-coroutines-timeout/index.html @@ -1,108 +1 @@ - - - - - CoroutinesTimeout - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CoroutinesTimeout

-
class CoroutinesTimeout(    testTimeoutMs: Long,     cancelOnTimeout: Boolean = false,     enableCoroutineCreationStackTraces: Boolean = true) : TestRule

Coroutines timeout rule for JUnit4 that is applied to all methods in the class. This rule is very similar to Timeout rule: it runs tests in a separate thread, fails tests after the given timeout and interrupts test thread.

Additionally, this rule installs DebugProbes and dumps all coroutines at the moment of the timeout. It may cancel coroutines on timeout if cancelOnTimeout set to true. enableCoroutineCreationStackTraces controls the corresponding DebugProbes.enableCreationStackTraces property and can be optionally disabled to speed-up tests if creation stack traces are not needed.

Example of usage:

class HangingTest {
@get:Rule
val timeout = CoroutinesTimeout.seconds(5)

@Test
fun testThatHangs() = runBlocking {
...
delay(Long.MAX_VALUE) // somewhere deep in the stack
...
}
}
-
-
-
-
-

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
fun CoroutinesTimeout(testTimeoutMs: Long, cancelOnTimeout: Boolean = false)
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun CoroutinesTimeout(    testTimeoutMs: Long,     cancelOnTimeout: Boolean = false,     enableCoroutineCreationStackTraces: Boolean = true)
-
-
-
-
-
-

Types

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
object Companion
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit4/index.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit4/index.html index f3e78f4cbd..57c4764310 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit4/index.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit4/index.html @@ -1,75 +1 @@ - - - - - kotlinx.coroutines.debug.junit4 - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Package kotlinx.coroutines.debug.junit4

-
-
-
-
-

Types

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
class CoroutinesTimeout(    testTimeoutMs: Long,     cancelOnTimeout: Boolean = false,     enableCoroutineCreationStackTraces: Boolean = true) : TestRule

Coroutines timeout rule for JUnit4 that is applied to all methods in the class. This rule is very similar to Timeout rule: it runs tests in a separate thread, fails tests after the given timeout and interrupts test thread.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit5/-coroutines-timeout/-coroutines-timeout.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit5/-coroutines-timeout/-coroutines-timeout.html index 7c63ff49a8..926091a8b6 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit5/-coroutines-timeout/-coroutines-timeout.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit5/-coroutines-timeout/-coroutines-timeout.html @@ -1,54 +1 @@ - - - - - CoroutinesTimeout - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CoroutinesTimeout

-
-
fun CoroutinesTimeout(testTimeoutMs: Long, cancelOnTimeout: Boolean = false)
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit5/-coroutines-timeout/cancel-on-timeout.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit5/-coroutines-timeout/cancel-on-timeout.html index 9e9e6b63aa..9e1c82b6b4 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit5/-coroutines-timeout/cancel-on-timeout.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit5/-coroutines-timeout/cancel-on-timeout.html @@ -1,54 +1 @@ - - - - - cancelOnTimeout - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

cancelOnTimeout

-
-
val cancelOnTimeout: Boolean = false
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit5/-coroutines-timeout/index.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit5/-coroutines-timeout/index.html index 2a22331686..6f10b50a13 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit5/-coroutines-timeout/index.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit5/-coroutines-timeout/index.html @@ -1,112 +1 @@ - - - - - CoroutinesTimeout - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CoroutinesTimeout

-
annotation class CoroutinesTimeout(val testTimeoutMs: Long, val cancelOnTimeout: Boolean = false)

Coroutines timeout annotation that is similar to JUnit5's Timeout annotation. It allows running test methods in a separate thread, failing them after the provided time limit and interrupting the thread.

Additionally, it installs DebugProbes and dumps all coroutines at the moment of the timeout. It also cancels coroutines on timeout if cancelOnTimeout set to true. The dump contains the coroutine creation stack traces.

This annotation has an effect on test, test factory, test template, and lifecycle methods and test classes that are annotated with it.

Annotating a class is the same as annotating every test, test factory, and test template method (but not lifecycle methods) of that class and its inner test classes, unless any of them is annotated with CoroutinesTimeout, in which case their annotation overrides the one on the containing class.

Declaring CoroutinesTimeout on a test factory checks that it finishes in the specified time, but does not check whether the methods that it produces obey the timeout as well.

Example usage:

@CoroutinesTimeout(100)
class CoroutinesTimeoutSimpleTest {
// does not time out, as the annotation on the method overrides the class-level one
@CoroutinesTimeout(1000)
@Test
fun classTimeoutIsOverridden() {
runBlocking {
delay(150)
}
}

// times out in 100 ms, timeout value is taken from the class-level annotation
@Test
fun classTimeoutIsUsed() {
runBlocking {
delay(150)
}
}
}
-
-
-
-
-

See also

-
-
org.junit.jupiter.api.Timeout
-
-

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
fun CoroutinesTimeout(testTimeoutMs: Long, cancelOnTimeout: Boolean = false)
-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
val cancelOnTimeout: Boolean = false
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
val testTimeoutMs: Long
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit5/-coroutines-timeout/test-timeout-ms.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit5/-coroutines-timeout/test-timeout-ms.html index 824b9b0bdf..19dea5c621 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit5/-coroutines-timeout/test-timeout-ms.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit5/-coroutines-timeout/test-timeout-ms.html @@ -1,54 +1 @@ - - - - - testTimeoutMs - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

testTimeoutMs

-
-
val testTimeoutMs: Long
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit5/index.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit5/index.html index 1b29c2544a..682d464390 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit5/index.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug.junit5/index.html @@ -1,75 +1 @@ - - - - - kotlinx.coroutines.debug.junit5 - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Package kotlinx.coroutines.debug.junit5

-
-
-
-
-

Types

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
annotation class CoroutinesTimeout(val testTimeoutMs: Long, val cancelOnTimeout: Boolean = false)

Coroutines timeout annotation that is similar to JUnit5's Timeout annotation. It allows running test methods in a separate thread, failing them after the provided time limit and interrupting the thread.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/context.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/context.html index 3d78dfc9ad..37d3541e54 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/context.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/context.html @@ -1,54 +1 @@ - - - - - context - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

context

-
-
val context: CoroutineContext

Coroutine context of the coroutine

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/creation-stack-trace.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/creation-stack-trace.html index 26c93a7c47..a2b9c2cdc0 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/creation-stack-trace.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/creation-stack-trace.html @@ -1,54 +1 @@ - - - - - creationStackTrace - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

creationStackTrace

-
-
val creationStackTrace: List<StackTraceElement>

Creation stacktrace of the coroutine. Can be empty if DebugProbes.enableCreationStackTraces is not set.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/index.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/index.html index 727e703dc7..9bc0182043 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/index.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/index.html @@ -1,153 +1 @@ - - - - - CoroutineInfo - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CoroutineInfo

-
class CoroutineInfo

Class describing coroutine info such as its context, state and stacktrace.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
fun lastObservedStackTrace(): List<StackTraceElement>

Last observed stacktrace of the coroutine captured on its suspension or resumption point. It means that for running coroutines resulting stacktrace is inaccurate and reflects stacktrace of the resumption point, not the actual current stacktrace.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
open override fun toString(): String
-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
val context: CoroutineContext

Coroutine context of the coroutine

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
val creationStackTrace: List<StackTraceElement>

Creation stacktrace of the coroutine. Can be empty if DebugProbes.enableCreationStackTraces is not set.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
val job: Job?

Job associated with a current coroutine or null. May be later used in DebugProbes.printJob.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
val state: State

Last observed state of the coroutine

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/job.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/job.html index ff963e0a88..0ac307d081 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/job.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/job.html @@ -1,54 +1 @@ - - - - - job - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

job

-
-
val job: Job?

Job associated with a current coroutine or null. May be later used in DebugProbes.printJob.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/last-observed-stack-trace.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/last-observed-stack-trace.html index 701a6ba1a4..097524e406 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/last-observed-stack-trace.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/last-observed-stack-trace.html @@ -1,54 +1 @@ - - - - - lastObservedStackTrace - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

lastObservedStackTrace

-
-
fun lastObservedStackTrace(): List<StackTraceElement>

Last observed stacktrace of the coroutine captured on its suspension or resumption point. It means that for running coroutines resulting stacktrace is inaccurate and reflects stacktrace of the resumption point, not the actual current stacktrace.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/state.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/state.html index ef3ccb0a27..14ef5292eb 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/state.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/state.html @@ -1,54 +1 @@ - - - - - state - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

state

-
-
val state: State

Last observed state of the coroutine

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/to-string.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/to-string.html index 33afff9c58..1bed467086 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/to-string.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutine-info/to-string.html @@ -1,54 +1 @@ - - - - - toString - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

toString

-
-
open override fun toString(): String
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutines-block-hound-integration/-coroutines-block-hound-integration.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutines-block-hound-integration/-coroutines-block-hound-integration.html index d64d1a6b61..5c8ae588d1 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutines-block-hound-integration/-coroutines-block-hound-integration.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutines-block-hound-integration/-coroutines-block-hound-integration.html @@ -1,54 +1 @@ - - - - - CoroutinesBlockHoundIntegration - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CoroutinesBlockHoundIntegration

-
-
fun CoroutinesBlockHoundIntegration()
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutines-block-hound-integration/apply-to.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutines-block-hound-integration/apply-to.html index 809e76a373..0fbb3a7d83 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutines-block-hound-integration/apply-to.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutines-block-hound-integration/apply-to.html @@ -1,54 +1 @@ - - - - - applyTo - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

applyTo

-
-
open override fun applyTo(builder: BlockHound.Builder)
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutines-block-hound-integration/index.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutines-block-hound-integration/index.html index 9eb8bd11e0..c28f2c968d 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutines-block-hound-integration/index.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-coroutines-block-hound-integration/index.html @@ -1,93 +1 @@ - - - - - CoroutinesBlockHoundIntegration - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CoroutinesBlockHoundIntegration

-
class CoroutinesBlockHoundIntegration : BlockHoundIntegration
-
-
-
-
-

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
fun CoroutinesBlockHoundIntegration()
-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
open override fun applyTo(builder: BlockHound.Builder)
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/dump-coroutines-info.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/dump-coroutines-info.html index 601cecb3df..f037e08d80 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/dump-coroutines-info.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/dump-coroutines-info.html @@ -1,54 +1 @@ - - - - - dumpCoroutinesInfo - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

dumpCoroutinesInfo

-
-
fun dumpCoroutinesInfo(): List<CoroutineInfo>

Returns all existing coroutines info. The resulting collection represents a consistent snapshot of all existing coroutines at the moment of invocation.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/dump-coroutines.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/dump-coroutines.html index 100685e46e..eac2d47e88 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/dump-coroutines.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/dump-coroutines.html @@ -1,54 +1 @@ - - - - - dumpCoroutines - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

dumpCoroutines

-
-
fun dumpCoroutines(out: PrintStream = System.out)

Dumps all active coroutines into the given output stream, providing a consistent snapshot of all existing coroutines at the moment of invocation. The output of this method is similar to jstack or a full thread dump. It can be used as the replacement to "Dump threads" action.

Example of the output:

Coroutines dump 2018/11/12 19:45:14

Coroutine "coroutine#42":StandaloneCoroutine{Active}@58fdd99, state: SUSPENDED
at MyClass$awaitData.invokeSuspend(MyClass.kt:37)
(Coroutine creation stacktrace)
at MyClass.createIoRequest(MyClass.kt:142)
at MyClass.fetchData(MyClass.kt:154)
at MyClass.showData(MyClass.kt:31)
...
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/enable-creation-stack-traces.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/enable-creation-stack-traces.html index 7a569a7ef2..44bfd6db48 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/enable-creation-stack-traces.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/enable-creation-stack-traces.html @@ -1,54 +1 @@ - - - - - enableCreationStackTraces - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

enableCreationStackTraces

-
-
var enableCreationStackTraces: Boolean

Whether coroutine creation stack traces should be captured. When enabled, for each created coroutine a stack trace of the current thread is captured and attached to the coroutine. This option can be useful during local debug sessions, but is recommended to be disabled in production environments to avoid stack trace dumping overhead.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/index.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/index.html index 216533d3b4..fd3e148e75 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/index.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/index.html @@ -1,243 +1 @@ - - - - - DebugProbes - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

DebugProbes

-
object DebugProbes

Debug probes support.

Debug probes is a dynamic attach mechanism which installs multiple hooks into coroutines machinery. It slows down all coroutine-related code, but in return provides a lot of diagnostic information, including asynchronous stack-traces and coroutine dumps (similar to ThreadMXBean.dumpAllThreads and jstack via DebugProbes.dumpCoroutines. All introspecting methods throw IllegalStateException if debug probes were not installed.

Installed hooks:

  • probeCoroutineResumed is invoked on every Continuation.resume.

  • probeCoroutineSuspended is invoked on every continuation suspension.

  • probeCoroutineCreated is invoked on every coroutine creation using stdlib intrinsics.

Overhead:

  • Every created coroutine is stored in a concurrent hash map and hash map is looked up and updated on each suspension and resumption.

  • If DebugProbes.enableCreationStackTraces is enabled, stack trace of the current thread is captured on each created coroutine that is a rough equivalent of throwing an exception per each created coroutine.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
fun dumpCoroutines(out: PrintStream = System.out)

Dumps all active coroutines into the given output stream, providing a consistent snapshot of all existing coroutines at the moment of invocation. The output of this method is similar to jstack or a full thread dump. It can be used as the replacement to "Dump threads" action.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun dumpCoroutinesInfo(): List<CoroutineInfo>

Returns all existing coroutines info. The resulting collection represents a consistent snapshot of all existing coroutines at the moment of invocation.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun install()

Installs a DebugProbes instead of no-op stdlib probes by redefining debug probes class using the same class loader as one loaded DebugProbes class.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun jobToString(job: Job): String

Returns string representation of the coroutines job hierarchy with additional debug information. Hierarchy is printed from the job as a root transitively to all children.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun printJob(job: Job, out: PrintStream = System.out)

Prints job hierarchy representation from jobToString to the given out.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun printScope(scope: CoroutineScope, out: PrintStream = System.out)

Prints all coroutines launched within the given scope. Throws IllegalStateException if the scope has no a job in it.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun scopeToString(scope: CoroutineScope): String

Returns string representation of all coroutines launched within the given scope. Throws IllegalStateException if the scope has no a job in it.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun uninstall()

Uninstall debug probes.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
inline fun withDebugProbes(block: () -> Unit)

Invokes given block of code with installed debug probes and uninstall probes in the end.

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
var enableCreationStackTraces: Boolean

Whether coroutine creation stack traces should be captured. When enabled, for each created coroutine a stack trace of the current thread is captured and attached to the coroutine. This option can be useful during local debug sessions, but is recommended to be disabled in production environments to avoid stack trace dumping overhead.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
val isInstalled: Boolean

Determines whether debug probes were installed.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
var sanitizeStackTraces: Boolean

Whether coroutine creation stack traces should be sanitized. Sanitization removes all frames from kotlinx.coroutines package except the first one and the last one to simplify diagnostic.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/install.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/install.html index df6e38b369..ce2426c0e1 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/install.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/install.html @@ -1,54 +1 @@ - - - - - install - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

install

-
-
fun install()

Installs a DebugProbes instead of no-op stdlib probes by redefining debug probes class using the same class loader as one loaded DebugProbes class.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/is-installed.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/is-installed.html index 77c056a9e2..8bcec0355a 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/is-installed.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/is-installed.html @@ -1,54 +1 @@ - - - - - isInstalled - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

isInstalled

-
-
val isInstalled: Boolean

Determines whether debug probes were installed.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/job-to-string.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/job-to-string.html index de579cf136..fedb13666b 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/job-to-string.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/job-to-string.html @@ -1,54 +1 @@ - - - - - jobToString - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

jobToString

-
-
fun jobToString(job: Job): String

Returns string representation of the coroutines job hierarchy with additional debug information. Hierarchy is printed from the job as a root transitively to all children.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/print-job.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/print-job.html index 3378842042..7473fbbdc0 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/print-job.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/print-job.html @@ -1,54 +1 @@ - - - - - printJob - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

printJob

-
-
fun printJob(job: Job, out: PrintStream = System.out)

Prints job hierarchy representation from jobToString to the given out.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/print-scope.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/print-scope.html index dafd4517dd..c462525d64 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/print-scope.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/print-scope.html @@ -1,54 +1 @@ - - - - - printScope - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

printScope

-
-
fun printScope(scope: CoroutineScope, out: PrintStream = System.out)

Prints all coroutines launched within the given scope. Throws IllegalStateException if the scope has no a job in it.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/sanitize-stack-traces.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/sanitize-stack-traces.html index 07a51616d7..27cced9b9b 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/sanitize-stack-traces.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/sanitize-stack-traces.html @@ -1,54 +1 @@ - - - - - sanitizeStackTraces - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

sanitizeStackTraces

-
-
var sanitizeStackTraces: Boolean

Whether coroutine creation stack traces should be sanitized. Sanitization removes all frames from kotlinx.coroutines package except the first one and the last one to simplify diagnostic.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/scope-to-string.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/scope-to-string.html index 132210f058..666a947700 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/scope-to-string.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/scope-to-string.html @@ -1,54 +1 @@ - - - - - scopeToString - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

scopeToString

-
-
fun scopeToString(scope: CoroutineScope): String

Returns string representation of all coroutines launched within the given scope. Throws IllegalStateException if the scope has no a job in it.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/uninstall.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/uninstall.html index 32032f26e1..a555423c55 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/uninstall.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/uninstall.html @@ -1,54 +1 @@ - - - - - uninstall - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

uninstall

-
-
fun uninstall()

Uninstall debug probes.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/with-debug-probes.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/with-debug-probes.html index 012cee9c99..540a53d82d 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/with-debug-probes.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-debug-probes/with-debug-probes.html @@ -1,54 +1 @@ - - - - - withDebugProbes - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

withDebugProbes

-
-
inline fun withDebugProbes(block: () -> Unit)

Invokes given block of code with installed debug probes and uninstall probes in the end.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-state/-c-r-e-a-t-e-d/index.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-state/-c-r-e-a-t-e-d/index.html index 173c3dcd5e..2cc1b6388a 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-state/-c-r-e-a-t-e-d/index.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-state/-c-r-e-a-t-e-d/index.html @@ -1,58 +1 @@ - - - - - CREATED - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

CREATED

-

Created, but not yet started.

-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-state/-r-u-n-n-i-n-g/index.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-state/-r-u-n-n-i-n-g/index.html index 980184cb1c..68364a64b3 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-state/-r-u-n-n-i-n-g/index.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-state/-r-u-n-n-i-n-g/index.html @@ -1,58 +1 @@ - - - - - RUNNING - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

RUNNING

-

Started and running.

-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-state/-s-u-s-p-e-n-d-e-d/index.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-state/-s-u-s-p-e-n-d-e-d/index.html index 54756fad87..f2d0d6f158 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-state/-s-u-s-p-e-n-d-e-d/index.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-state/-s-u-s-p-e-n-d-e-d/index.html @@ -1,58 +1 @@ - - - - - SUSPENDED - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

SUSPENDED

-

Suspended.

-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-state/index.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-state/index.html index 246e2167c1..914fba6d2e 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-state/index.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/-state/index.html @@ -1,106 +1 @@ - - - - - State - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

State

-
enum State : Enum<State>

Current state of the coroutine.

-
-
-
-
-

Entries

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-

Suspended.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-

Started and running.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-

Created, but not yet started.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/index.html b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/index.html index 1da9d0fc38..e40b323354 100644 --- a/kotlinx-coroutines-debug/kotlinx.coroutines.debug/index.html +++ b/kotlinx-coroutines-debug/kotlinx.coroutines.debug/index.html @@ -1,120 +1 @@ - - - - - kotlinx.coroutines.debug - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Package kotlinx.coroutines.debug

-
-
-
-
-

Types

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
class CoroutineInfo

Class describing coroutine info such as its context, state and stacktrace.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
class CoroutinesBlockHoundIntegration : BlockHoundIntegration
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
object DebugProbes

Debug probes support.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
enum State : Enum<State>

Current state of the coroutine.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-debug/navigation.html b/kotlinx-coroutines-debug/navigation.html deleted file mode 100644 index be03fe14df..0000000000 --- a/kotlinx-coroutines-debug/navigation.html +++ /dev/null @@ -1,2047 +0,0 @@ -
- -
- -
- - - -
- -
-
- -
-
- -
-
-
- async() -
-
-
-
- await() -
-
-
- -
- - -
-
- cancel() -
-
-
- -
- - - - - - - - -
- -
-
- -
- - - - - -
- -
-
- -
- - -
- -
-
- ATOMIC -
-
-
-
- DEFAULT -
-
-
-
- LAZY -
-
-
- -
-
- - - - - -
-
- Deferred -
-
-
-
- delay() -
-
- -
- -
- -
- -
-
- -
- - -
- -
-
- -
- - -
-
- invoke() -
-
- -
-
- isActive -
-
-
- -
-
-
- Job -
-
-
-
- job -
-
-
-
- Job() -
-
-
-
- joinAll() -
-
-
-
- launch() -
-
- -
- -
- - - -
- -
- -
-
- plus() -
-
-
-
- promise() -
-
-
- -
- -
-
- Runnable -
-
-
- -
-
- -
- - - - -
- -
-
- -
- -
-
- yield() -
-
-
-
- -
-
- actor() -
-
-
- -
-
- -
-
- -
- - -
- -
- -
-
- -
-
-
- SUSPEND -
-
-
-
-
- Channel -
-
-
-
- Channel() -
-
-
- -
-
- -
- - - -
-
- consume() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- produce() -
-
-
- -
-
- -
-
- -
-
-
- ticker() -
-
-
- -
- -
-
- -
-
-
-
- toList() -
-
- -
-
- -
- -
-
-
- asFlow() -
-
-
- -
-
- -
-
-
- buffer() -
-
-
- -
-
- -
-
-
- catch() -
-
-
- -
-
-
- collect() -
-
- -
- -
-
-
- combine() -
-
- -
- -
-
- -
-
-
- count() -
-
-
- -
- - - - -
-
- drop() -
-
-
- -
-
-
- emitAll() -
-
-
- -
-
-
- filter() -
-
- -
- -
-
- -
-
-
- first() -
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
- Flow -
-
-
-
- flow() -
-
-
- -
-
-
- flowOf() -
-
-
-
- flowOn() -
-
-
-
- fold() -
-
-
- -
-
-
- last() -
-
-
- -
-
- -
-
-
- map() -
-
-
- -
-
- -
-
-
- merge() -
-
- - - - -
- -
-
-
- onEach() -
-
-
-
- onEmpty() -
-
-
-
- onStart() -
-
- -
- -
-
- -
-
-
- reduce() -
-
-
-
- retry() -
-
-
- -
-
- -
-
- -
-
-
- sample() -
-
-
-
- scan() -
-
-
- -
-
-
- shareIn() -
-
-
- -
-
- START -
-
-
-
- STOP -
-
- -
-
- -
-
-
- single() -
-
-
- -
-
-
- StateFlow -
-
-
-
- stateIn() -
-
-
-
- take() -
-
-
- -
-
- -
-
-
- toList() -
-
-
-
- toSet() -
-
-
- -
- - -
-
- update() -
-
-
- -
- -
- -
-
-
- zip() -
-
-
- -
- -
- -
-
-
- select() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- -
-
- Mutex -
-
-
-
- Mutex() -
-
-
-
- Semaphore -
-
-
- -
-
- -
-
- -
-
-
- -
- -
- -
- -
- -
-
- await() -
-
-
-
- future() -
-
-
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
-
- JavaFx -
-
- -
-
-
- -
- - -
- -
-
-
- await() -
-
-
-
- future() -
-
-
- -
- -
- -
-
-
- delay() -
-
-
- -
-
-
- sample() -
-
-
- -
- -
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
- -
-
-
- -
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
-
- publish() -
-
-
-
- -
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
-
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
- - - -
diff --git a/kotlinx-coroutines-guava/index.html b/kotlinx-coroutines-guava/index.html index 0432834251..1d683c5b09 100644 --- a/kotlinx-coroutines-guava/index.html +++ b/kotlinx-coroutines-guava/index.html @@ -1,70 +1 @@ - - - - - kotlinx-coroutines-guava - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

kotlinx-coroutines-guava

-

Integration with Guava ListenableFuture.

Coroutine builders:

NameResultScopeDescription
futureListenableFutureCoroutineScopeReturns a single value with the future result

Extension functions:

NameDescription
com.google.common.util.concurrent.ListenableFuture.awaitAwaits for completion of the future (cancellable)
kotlinx.coroutines.Deferred.asListenableFutureConverts a deferred value to the future

Example

Given the following functions defined in some Java API based on Guava:

public ListenableFuture<Image> loadImageAsync(String name); // starts async image loading
public Image combineImages(Image image1, Image image2); // synchronously combines two images using some algorithm

We can consume this API from Kotlin coroutine to load two images and combine then asynchronously. The resulting function returns ListenableFuture<Image> for ease of use back from Guava-based Java code.

fun combineImagesAsync(name1: String, name2: String): ListenableFuture<Image> = future {
val future1 = loadImageAsync(name1) // start loading first image
val future2 = loadImageAsync(name2) // start loading second image
combineImages(future1.await(), future2.await()) // wait for both, combine, and return result
}

Note that this module should be used only for integration with existing Java APIs based on ListenableFuture. Writing pure-Kotlin code that uses ListenableFuture is highly not recommended, since the resulting APIs based on the futures are quite error-prone. See the discussion on Asynchronous Programming Styles for details on general problems pertaining to any future-based API and keep in mind that ListenableFuture exposes a blocking method get that makes it especially bad choice for coroutine-based Kotlin code.

-
-

Packages

-
-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-guava/kotlinx.coroutines.guava/as-deferred.html b/kotlinx-coroutines-guava/kotlinx.coroutines.guava/as-deferred.html index 27d6b9748d..9f9941fcd7 100644 --- a/kotlinx-coroutines-guava/kotlinx.coroutines.guava/as-deferred.html +++ b/kotlinx-coroutines-guava/kotlinx.coroutines.guava/as-deferred.html @@ -1,54 +1 @@ - - - - - asDeferred - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asDeferred

-
-
fun <T> ListenableFuture<T>.asDeferred(): Deferred<T>

Returns a Deferred that is completed or failed by thisListenableFuture.

Completion is non-atomic between the two promises.

Cancellation is propagated bidirectionally.

When thisListenableFuture completes (either successfully or exceptionally) it will try to complete the returned Deferred with the same value or exception. This will succeed, barring a race with cancellation of the Deferred.

When thisListenableFuture is successfully cancelled, it will cancel the returned Deferred.

When the returned Deferred is cancelled, it will try to propagate the cancellation to thisListenableFuture. Propagation will succeed, barring a race with the ListenableFuture completing normally. This is the only case in which the returned Deferred will complete with a different outcome than thisListenableFuture.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-guava/kotlinx.coroutines.guava/as-listenable-future.html b/kotlinx-coroutines-guava/kotlinx.coroutines.guava/as-listenable-future.html index b72cf8bc25..6e743e0856 100644 --- a/kotlinx-coroutines-guava/kotlinx.coroutines.guava/as-listenable-future.html +++ b/kotlinx-coroutines-guava/kotlinx.coroutines.guava/as-listenable-future.html @@ -1,54 +1 @@ - - - - - asListenableFuture - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asListenableFuture

-
-
fun <T> Deferred<T>.asListenableFuture(): ListenableFuture<T>

Returns a ListenableFuture that is completed or failed by thisDeferred.

Completion is non-atomic between the two promises.

When either promise successfully completes, it will attempt to synchronously complete its counterpart with the same value. This will succeed barring a race with cancellation.

When either promise completes with an Exception, it will attempt to synchronously complete its counterpart with the same Exception. This will succeed barring a race with cancellation.

Cancellation is propagated bidirectionally.

When the returned Future is successfully cancelled - meaning Future.cancel returned true - Deferred.cancel will be synchronously called on thisDeferred. This will attempt to cancel the Deferred, though cancellation may not succeed and the Deferred may complete in a non-cancelled terminal state.

When thisDeferred reaches its "cancelled" state with a successful cancellation - meaning it completes with kotlinx.coroutines.CancellationException - thisDeferred will synchronously cancel the returned Future. This can only race with cancellation of the returned Future, so the returned Future will always eventually reach its cancelled state when either promise is successfully cancelled, for their different meanings of "successfully cancelled".

This is inherently a race. See Future.cancel for a description of Future cancellation semantics. See Job for a description of coroutine cancellation semantics. See JobListenableFuture.cancel for greater detail on the overlapped cancellation semantics and corner cases of this method.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-guava/kotlinx.coroutines.guava/await.html b/kotlinx-coroutines-guava/kotlinx.coroutines.guava/await.html index b7ed4f9b74..02ea06d66a 100644 --- a/kotlinx-coroutines-guava/kotlinx.coroutines.guava/await.html +++ b/kotlinx-coroutines-guava/kotlinx.coroutines.guava/await.html @@ -1,54 +1 @@ - - - - - await - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

await

-
-
suspend fun <T> ListenableFuture<T>.await(): T

Awaits completion of thisListenableFuture without blocking a thread.

This suspend function is cancellable.

If the Job of the current coroutine is cancelled or completed while this suspending function is waiting, this function stops waiting for the future and immediately resumes with CancellationException.

This method is intended to be used with one-shot Futures, so on coroutine cancellation, the Future is cancelled as well. If cancelling the given future is undesired, use Futures.nonCancellationPropagating or kotlinx.coroutines.NonCancellable.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-guava/kotlinx.coroutines.guava/future.html b/kotlinx-coroutines-guava/kotlinx.coroutines.guava/future.html index e8456510a1..6a4b043f5d 100644 --- a/kotlinx-coroutines-guava/kotlinx.coroutines.guava/future.html +++ b/kotlinx-coroutines-guava/kotlinx.coroutines.guava/future.html @@ -1,54 +1 @@ - - - - - future - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

future

-
-
fun <T> CoroutineScope.future(    context: CoroutineContext = EmptyCoroutineContext,     start: CoroutineStart = CoroutineStart.DEFAULT,     block: suspend CoroutineScope.() -> T): ListenableFuture<T>

Starts block in a new coroutine and returns a ListenableFuture pointing to its result.

The coroutine is started immediately. Passing CoroutineStart.LAZY to start throws IllegalArgumentException, because Futures don't have a way to start lazily.

When the created coroutine isCompleted, it will try to synchronously complete the returned Future with the same outcome. This will succeed, barring a race with external cancellation of returned ListenableFuture.

Cancellation is propagated bidirectionally.

CoroutineContext is inherited from this CoroutineScope. Additional context elements can be added/overlaid by passing context.

If the context does not have a CoroutineDispatcher, nor any other ContinuationInterceptor member, Dispatchers.Default is used.

The parent job is inherited from this CoroutineScope, and can be overridden by passing a Job in context.

See newCoroutineContext for a description of debugging facilities.

Note that the error and cancellation semantics of future are different than async's. In contrast to Deferred, Future doesn't have an intermediate Cancelling state. If the returned Future is successfully cancelled, and block throws afterward, the thrown error is dropped, and getting the Future's value will throw a CancellationException with no cause. This is to match the specification and behavior of java.util.concurrent.FutureTask.

Parameters

context

added overlaying CoroutineScope.coroutineContext to form the new context.

start

coroutine start option. The default value is CoroutineStart.DEFAULT.

block

the code to execute.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-guava/kotlinx.coroutines.guava/index.html b/kotlinx-coroutines-guava/kotlinx.coroutines.guava/index.html index aa2c97722b..068bf96966 100644 --- a/kotlinx-coroutines-guava/kotlinx.coroutines.guava/index.html +++ b/kotlinx-coroutines-guava/kotlinx.coroutines.guava/index.html @@ -1,120 +1 @@ - - - - - kotlinx.coroutines.guava - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Package kotlinx.coroutines.guava

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T> ListenableFuture<T>.asDeferred(): Deferred<T>

Returns a Deferred that is completed or failed by thisListenableFuture.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T> Deferred<T>.asListenableFuture(): ListenableFuture<T>

Returns a ListenableFuture that is completed or failed by thisDeferred.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> ListenableFuture<T>.await(): T

Awaits completion of thisListenableFuture without blocking a thread.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T> CoroutineScope.future(    context: CoroutineContext = EmptyCoroutineContext,     start: CoroutineStart = CoroutineStart.DEFAULT,     block: suspend CoroutineScope.() -> T): ListenableFuture<T>

Starts block in a new coroutine and returns a ListenableFuture pointing to its result.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-guava/navigation.html b/kotlinx-coroutines-guava/navigation.html deleted file mode 100644 index be03fe14df..0000000000 --- a/kotlinx-coroutines-guava/navigation.html +++ /dev/null @@ -1,2047 +0,0 @@ -
- -
- -
- - - -
- -
-
- -
-
- -
-
-
- async() -
-
-
-
- await() -
-
-
- -
- - -
-
- cancel() -
-
-
- -
- - - - - - - - -
- -
-
- -
- - - - - -
- -
-
- -
- - -
- -
-
- ATOMIC -
-
-
-
- DEFAULT -
-
-
-
- LAZY -
-
-
- -
-
- - - - - -
-
- Deferred -
-
-
-
- delay() -
-
- -
- -
- -
- -
-
- -
- - -
- -
-
- -
- - -
-
- invoke() -
-
- -
-
- isActive -
-
-
- -
-
-
- Job -
-
-
-
- job -
-
-
-
- Job() -
-
-
-
- joinAll() -
-
-
-
- launch() -
-
- -
- -
- - - -
- -
- -
-
- plus() -
-
-
-
- promise() -
-
-
- -
- -
-
- Runnable -
-
-
- -
-
- -
- - - - -
- -
-
- -
- -
-
- yield() -
-
-
-
- -
-
- actor() -
-
-
- -
-
- -
-
- -
- - -
- -
- -
-
- -
-
-
- SUSPEND -
-
-
-
-
- Channel -
-
-
-
- Channel() -
-
-
- -
-
- -
- - - -
-
- consume() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- produce() -
-
-
- -
-
- -
-
- -
-
-
- ticker() -
-
-
- -
- -
-
- -
-
-
-
- toList() -
-
- -
-
- -
- -
-
-
- asFlow() -
-
-
- -
-
- -
-
-
- buffer() -
-
-
- -
-
- -
-
-
- catch() -
-
-
- -
-
-
- collect() -
-
- -
- -
-
-
- combine() -
-
- -
- -
-
- -
-
-
- count() -
-
-
- -
- - - - -
-
- drop() -
-
-
- -
-
-
- emitAll() -
-
-
- -
-
-
- filter() -
-
- -
- -
-
- -
-
-
- first() -
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
- Flow -
-
-
-
- flow() -
-
-
- -
-
-
- flowOf() -
-
-
-
- flowOn() -
-
-
-
- fold() -
-
-
- -
-
-
- last() -
-
-
- -
-
- -
-
-
- map() -
-
-
- -
-
- -
-
-
- merge() -
-
- - - - -
- -
-
-
- onEach() -
-
-
-
- onEmpty() -
-
-
-
- onStart() -
-
- -
- -
-
- -
-
-
- reduce() -
-
-
-
- retry() -
-
-
- -
-
- -
-
- -
-
-
- sample() -
-
-
-
- scan() -
-
-
- -
-
-
- shareIn() -
-
-
- -
-
- START -
-
-
-
- STOP -
-
- -
-
- -
-
-
- single() -
-
-
- -
-
-
- StateFlow -
-
-
-
- stateIn() -
-
-
-
- take() -
-
-
- -
-
- -
-
-
- toList() -
-
-
-
- toSet() -
-
-
- -
- - -
-
- update() -
-
-
- -
- -
- -
-
-
- zip() -
-
-
- -
- -
- -
-
-
- select() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- -
-
- Mutex -
-
-
-
- Mutex() -
-
-
-
- Semaphore -
-
-
- -
-
- -
-
- -
-
-
- -
- -
- -
- -
- -
-
- await() -
-
-
-
- future() -
-
-
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
-
- JavaFx -
-
- -
-
-
- -
- - -
- -
-
-
- await() -
-
-
-
- future() -
-
-
- -
- -
- -
-
-
- delay() -
-
-
- -
-
-
- sample() -
-
-
- -
- -
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
- -
-
-
- -
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
-
- publish() -
-
-
-
- -
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
-
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
- - - -
diff --git a/kotlinx-coroutines-javafx/index.html b/kotlinx-coroutines-javafx/index.html index c38ca60b69..9f6bed0d29 100644 --- a/kotlinx-coroutines-javafx/index.html +++ b/kotlinx-coroutines-javafx/index.html @@ -1,72 +1 @@ - - - - - kotlinx-coroutines-javafx - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

kotlinx-coroutines-javafx

-

Provides Dispatchers.JavaFx context and Dispatchers.Main implementation for JavaFX UI applications.

Read Guide to UI programming with coroutines for tutorial on this module.

-
-

Packages

-
-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-

Provides Dispatchers.JavaFx context and Dispatchers.Main implementation for JavaFX UI applications.

-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-javafx/kotlinx.coroutines.javafx/-java-fx-dispatcher/index.html b/kotlinx-coroutines-javafx/kotlinx.coroutines.javafx/-java-fx-dispatcher/index.html index 31d99ee676..2cff8fbc36 100644 --- a/kotlinx-coroutines-javafx/kotlinx.coroutines.javafx/-java-fx-dispatcher/index.html +++ b/kotlinx-coroutines-javafx/kotlinx.coroutines.javafx/-java-fx-dispatcher/index.html @@ -1,58 +1 @@ - - - - - JavaFxDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

JavaFxDispatcher

-
sealed class JavaFxDispatcher : MainCoroutineDispatcher, Delay

Dispatcher for JavaFx application thread with support for awaitPulse.

This class provides type-safety and a point for future extensions.

-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-javafx/kotlinx.coroutines.javafx/-java-fx.html b/kotlinx-coroutines-javafx/kotlinx.coroutines.javafx/-java-fx.html index ea6d518800..915507a09b 100644 --- a/kotlinx-coroutines-javafx/kotlinx.coroutines.javafx/-java-fx.html +++ b/kotlinx-coroutines-javafx/kotlinx.coroutines.javafx/-java-fx.html @@ -1,54 +1 @@ - - - - - JavaFx - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

JavaFx

-
-
val Dispatchers.JavaFx: JavaFxDispatcher

Dispatches execution onto JavaFx application thread and provides native delay support.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-javafx/kotlinx.coroutines.javafx/as-flow.html b/kotlinx-coroutines-javafx/kotlinx.coroutines.javafx/as-flow.html index a0210173e8..60454ab657 100644 --- a/kotlinx-coroutines-javafx/kotlinx.coroutines.javafx/as-flow.html +++ b/kotlinx-coroutines-javafx/kotlinx.coroutines.javafx/as-flow.html @@ -1,54 +1 @@ - - - - - asFlow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asFlow

-
-
fun <T> ObservableValue<T>.asFlow(): Flow<T>

Creates an instance of a cold Flow that subscribes to the given ObservableValue and emits its values as they change. The resulting flow is conflated, meaning that if several values arrive in quick succession, only the last one will be emitted. Since this implementation uses ObservableValue.addListener, even if this ObservableValue supports lazy evaluation, eager computation will be enforced while the flow is being collected. All the calls to JavaFX API are performed in Dispatchers.JavaFx. This flow emits at least the initial value.

Operator fusion

Adjacent applications of flowOn, buffer, conflate, and produceIn to the result of asFlow are fused. conflate has no effect, as this flow is already conflated; one can use buffer to change that instead.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-javafx/kotlinx.coroutines.javafx/await-pulse.html b/kotlinx-coroutines-javafx/kotlinx.coroutines.javafx/await-pulse.html index f1c5dea080..c7686fe382 100644 --- a/kotlinx-coroutines-javafx/kotlinx.coroutines.javafx/await-pulse.html +++ b/kotlinx-coroutines-javafx/kotlinx.coroutines.javafx/await-pulse.html @@ -1,54 +1 @@ - - - - - awaitPulse - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitPulse

-
-
suspend fun awaitPulse(): Long

Suspends coroutine until next JavaFx pulse and returns time of the pulse on resumption. If the Job of the current coroutine is completed while this suspending function is waiting, this function immediately resumes with CancellationException.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-javafx/kotlinx.coroutines.javafx/index.html b/kotlinx-coroutines-javafx/kotlinx.coroutines.javafx/index.html index f5f1b5d4ec..876ceec3b4 100644 --- a/kotlinx-coroutines-javafx/kotlinx.coroutines.javafx/index.html +++ b/kotlinx-coroutines-javafx/kotlinx.coroutines.javafx/index.html @@ -1,125 +1 @@ - - - - - kotlinx.coroutines.javafx - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Package kotlinx.coroutines.javafx

-

Provides Dispatchers.JavaFx context and Dispatchers.Main implementation for JavaFX UI applications.

-
-
-
-
-

Types

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
sealed class JavaFxDispatcher : MainCoroutineDispatcher, Delay

Dispatcher for JavaFx application thread with support for awaitPulse.

-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T> ObservableValue<T>.asFlow(): Flow<T>

Creates an instance of a cold Flow that subscribes to the given ObservableValue and emits its values as they change. The resulting flow is conflated, meaning that if several values arrive in quick succession, only the last one will be emitted. Since this implementation uses ObservableValue.addListener, even if this ObservableValue supports lazy evaluation, eager computation will be enforced while the flow is being collected. All the calls to JavaFX API are performed in Dispatchers.JavaFx. This flow emits at least the initial value.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun awaitPulse(): Long

Suspends coroutine until next JavaFx pulse and returns time of the pulse on resumption. If the Job of the current coroutine is completed while this suspending function is waiting, this function immediately resumes with CancellationException.

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
val Dispatchers.JavaFx: JavaFxDispatcher

Dispatches execution onto JavaFx application thread and provides native delay support.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-javafx/navigation.html b/kotlinx-coroutines-javafx/navigation.html deleted file mode 100644 index be03fe14df..0000000000 --- a/kotlinx-coroutines-javafx/navigation.html +++ /dev/null @@ -1,2047 +0,0 @@ -
- -
- -
- - - -
- -
-
- -
-
- -
-
-
- async() -
-
-
-
- await() -
-
-
- -
- - -
-
- cancel() -
-
-
- -
- - - - - - - - -
- -
-
- -
- - - - - -
- -
-
- -
- - -
- -
-
- ATOMIC -
-
-
-
- DEFAULT -
-
-
-
- LAZY -
-
-
- -
-
- - - - - -
-
- Deferred -
-
-
-
- delay() -
-
- -
- -
- -
- -
-
- -
- - -
- -
-
- -
- - -
-
- invoke() -
-
- -
-
- isActive -
-
-
- -
-
-
- Job -
-
-
-
- job -
-
-
-
- Job() -
-
-
-
- joinAll() -
-
-
-
- launch() -
-
- -
- -
- - - -
- -
- -
-
- plus() -
-
-
-
- promise() -
-
-
- -
- -
-
- Runnable -
-
-
- -
-
- -
- - - - -
- -
-
- -
- -
-
- yield() -
-
-
-
- -
-
- actor() -
-
-
- -
-
- -
-
- -
- - -
- -
- -
-
- -
-
-
- SUSPEND -
-
-
-
-
- Channel -
-
-
-
- Channel() -
-
-
- -
-
- -
- - - -
-
- consume() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- produce() -
-
-
- -
-
- -
-
- -
-
-
- ticker() -
-
-
- -
- -
-
- -
-
-
-
- toList() -
-
- -
-
- -
- -
-
-
- asFlow() -
-
-
- -
-
- -
-
-
- buffer() -
-
-
- -
-
- -
-
-
- catch() -
-
-
- -
-
-
- collect() -
-
- -
- -
-
-
- combine() -
-
- -
- -
-
- -
-
-
- count() -
-
-
- -
- - - - -
-
- drop() -
-
-
- -
-
-
- emitAll() -
-
-
- -
-
-
- filter() -
-
- -
- -
-
- -
-
-
- first() -
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
- Flow -
-
-
-
- flow() -
-
-
- -
-
-
- flowOf() -
-
-
-
- flowOn() -
-
-
-
- fold() -
-
-
- -
-
-
- last() -
-
-
- -
-
- -
-
-
- map() -
-
-
- -
-
- -
-
-
- merge() -
-
- - - - -
- -
-
-
- onEach() -
-
-
-
- onEmpty() -
-
-
-
- onStart() -
-
- -
- -
-
- -
-
-
- reduce() -
-
-
-
- retry() -
-
-
- -
-
- -
-
- -
-
-
- sample() -
-
-
-
- scan() -
-
-
- -
-
-
- shareIn() -
-
-
- -
-
- START -
-
-
-
- STOP -
-
- -
-
- -
-
-
- single() -
-
-
- -
-
-
- StateFlow -
-
-
-
- stateIn() -
-
-
-
- take() -
-
-
- -
-
- -
-
-
- toList() -
-
-
-
- toSet() -
-
-
- -
- - -
-
- update() -
-
-
- -
- -
- -
-
-
- zip() -
-
-
- -
- -
- -
-
-
- select() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- -
-
- Mutex -
-
-
-
- Mutex() -
-
-
-
- Semaphore -
-
-
- -
-
- -
-
- -
-
-
- -
- -
- -
- -
- -
-
- await() -
-
-
-
- future() -
-
-
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
-
- JavaFx -
-
- -
-
-
- -
- - -
- -
-
-
- await() -
-
-
-
- future() -
-
-
- -
- -
- -
-
-
- delay() -
-
-
- -
-
-
- sample() -
-
-
- -
- -
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
- -
-
-
- -
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
-
- publish() -
-
-
-
- -
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
-
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
- - - -
diff --git a/kotlinx-coroutines-jdk8/index.html b/kotlinx-coroutines-jdk8/index.html index 4b81d9fbc5..c537f63ca8 100644 --- a/kotlinx-coroutines-jdk8/index.html +++ b/kotlinx-coroutines-jdk8/index.html @@ -1,100 +1 @@ - - - - - kotlinx-coroutines-jdk8 - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

kotlinx-coroutines-jdk8

-

Integration with JDK8 CompletableFuture (Android API level 24).

Coroutine builders:

NameResultScopeDescription
futureCompletableFutureCoroutineScopeReturns a single value with the future result

Extension functions:

NameDescription
java.util.concurrent.CompletionStage.awaitAwaits for completion of the completion stage
java.util.concurrent.CompletionStage.asDeferredConverts completion stage to an instance of Deferred
kotlinx.coroutines.Deferred.asCompletableFutureConverts a deferred value to the future

Example

Given the following functions defined in some Java API:

public CompletableFuture<Image> loadImageAsync(String name); // starts async image loading
public Image combineImages(Image image1, Image image2); // synchronously combines two images using some algorithm

We can consume this API from Kotlin coroutine to load two images and combine then asynchronously. The resulting function returns CompletableFuture<Image> for ease of use back from Java.

fun combineImagesAsync(name1: String, name2: String): CompletableFuture<Image> = future {
val future1 = loadImageAsync(name1) // start loading first image
val future2 = loadImageAsync(name2) // start loading second image
combineImages(future1.await(), future2.await()) // wait for both, combine, and return result
}

Note that this module should be used only for integration with existing Java APIs based on CompletableFuture. Writing pure-Kotlin code that uses CompletableFuture is highly not recommended, since the resulting APIs based on the futures are quite error-prone. See the discussion on Asynchronous Programming Styles for details on general problems pertaining to any future-based API and keep in mind that CompletableFuture exposes a blocking method get that makes it especially bad choice for coroutine-based Kotlin code.

-
-

Packages

-
-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-

Integration with JDK8 CompletableFuture (Android API level 24).

-
-
-
- -
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
- -
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/as-completable-future.html b/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/as-completable-future.html index f32979fab9..26c31a252b 100644 --- a/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/as-completable-future.html +++ b/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/as-completable-future.html @@ -1,54 +1 @@ - - - - - asCompletableFuture - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asCompletableFuture

-
-
fun <T> Deferred<T>.asCompletableFuture(): CompletableFuture<T>

Converts this deferred value to the instance of CompletableFuture. The deferred value is cancelled when the resulting future is cancelled or otherwise completed.


fun Job.asCompletableFuture(): CompletableFuture<Unit>

Converts this job to the instance of CompletableFuture. The job is cancelled when the resulting future is cancelled or otherwise completed.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/as-deferred.html b/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/as-deferred.html index bfe198c093..f39fb888ee 100644 --- a/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/as-deferred.html +++ b/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/as-deferred.html @@ -1,54 +1 @@ - - - - - asDeferred - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asDeferred

-
-
fun <T> CompletionStage<T>.asDeferred(): Deferred<T>

Converts this CompletionStage to an instance of Deferred.

The CompletableFuture that corresponds to this CompletionStage (see CompletionStage.toCompletableFuture) is cancelled when the resulting deferred is cancelled.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/await.html b/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/await.html index b04cbe5065..a575858433 100644 --- a/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/await.html +++ b/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/await.html @@ -1,54 +1 @@ - - - - - await - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

await

-
-
suspend fun <T> CompletionStage<T>.await(): T

Awaits for completion of CompletionStage without blocking a thread.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this suspending function is waiting, this function stops waiting for the completion stage and immediately resumes with CancellationException.

This method is intended to be used with one-shot futures, so on coroutine cancellation the CompletableFuture that corresponds to this CompletionStage (see CompletionStage.toCompletableFuture) is cancelled. If cancelling the given stage is undesired, stage.asDeferred().await() should be used instead.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/future.html b/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/future.html index e3caed4eb1..2f6c7c87d8 100644 --- a/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/future.html +++ b/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/future.html @@ -1,54 +1 @@ - - - - - future - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

future

-
-
fun <T> CoroutineScope.future(    context: CoroutineContext = EmptyCoroutineContext,     start: CoroutineStart = CoroutineStart.DEFAULT,     block: suspend CoroutineScope.() -> T): CompletableFuture<T>

Starts a new coroutine and returns its result as an implementation of CompletableFuture. The running coroutine is cancelled when the resulting future is cancelled or otherwise completed.

The coroutine context is inherited from a CoroutineScope, additional context elements can be specified with the context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. The parent job is inherited from a CoroutineScope as well, but it can also be overridden with corresponding context element.

By default, the coroutine is immediately scheduled for execution. Other options can be specified via start parameter. See CoroutineStart for details. A value of CoroutineStart.LAZY is not supported (since CompletableFuture framework does not provide the corresponding capability) and produces IllegalArgumentException.

See newCoroutineContext for a description of debugging facilities that are available for newly created coroutine.

Parameters

context

additional to CoroutineScope.coroutineContext context of the coroutine.

start

coroutine start option. The default value is CoroutineStart.DEFAULT.

block

the coroutine code.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/index.html b/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/index.html index 8d65514e36..d6434277f8 100644 --- a/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/index.html +++ b/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/index.html @@ -1,121 +1 @@ - - - - - kotlinx.coroutines.future - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Package kotlinx.coroutines.future

-

Integration with JDK8 CompletableFuture (Android API level 24).

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T> Deferred<T>.asCompletableFuture(): CompletableFuture<T>

Converts this deferred value to the instance of CompletableFuture. The deferred value is cancelled when the resulting future is cancelled or otherwise completed.

fun Job.asCompletableFuture(): CompletableFuture<Unit>

Converts this job to the instance of CompletableFuture. The job is cancelled when the resulting future is cancelled or otherwise completed.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T> CompletionStage<T>.asDeferred(): Deferred<T>

Converts this CompletionStage to an instance of Deferred.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> CompletionStage<T>.await(): T

Awaits for completion of CompletionStage without blocking a thread.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T> CoroutineScope.future(    context: CoroutineContext = EmptyCoroutineContext,     start: CoroutineStart = CoroutineStart.DEFAULT,     block: suspend CoroutineScope.() -> T): CompletableFuture<T>

Starts a new coroutine and returns its result as an implementation of CompletableFuture. The running coroutine is cancelled when the resulting future is cancelled or otherwise completed.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk8/kotlinx.coroutines.stream/consume-as-flow.html b/kotlinx-coroutines-jdk8/kotlinx.coroutines.stream/consume-as-flow.html index 9cd0345af3..b31535c5e5 100644 --- a/kotlinx-coroutines-jdk8/kotlinx.coroutines.stream/consume-as-flow.html +++ b/kotlinx-coroutines-jdk8/kotlinx.coroutines.stream/consume-as-flow.html @@ -1,54 +1 @@ - - - - - consumeAsFlow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

consumeAsFlow

-
-
fun <T> Stream<T>.consumeAsFlow(): Flow<T>

Represents the given stream as a flow and closes the stream afterwards. The resulting flow can be collected only once and throws IllegalStateException when trying to collect it more than once.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk8/kotlinx.coroutines.stream/index.html b/kotlinx-coroutines-jdk8/kotlinx.coroutines.stream/index.html index 99f7770514..69ecd6d392 100644 --- a/kotlinx-coroutines-jdk8/kotlinx.coroutines.stream/index.html +++ b/kotlinx-coroutines-jdk8/kotlinx.coroutines.stream/index.html @@ -1,75 +1 @@ - - - - - kotlinx.coroutines.stream - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Package kotlinx.coroutines.stream

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T> Stream<T>.consumeAsFlow(): Flow<T>

Represents the given stream as a flow and closes the stream afterwards. The resulting flow can be collected only once and throws IllegalStateException when trying to collect it more than once.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/debounce.html b/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/debounce.html index 078f82a044..d1413a7cc0 100644 --- a/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/debounce.html +++ b/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/debounce.html @@ -1,54 +1 @@ - - - - - debounce - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

debounce

-
-
fun <T> Flow<T>.debounce(timeout: Duration): Flow<T>

"java.time" adapter method for kotlinx.coroutines.flow.debounce.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/delay.html b/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/delay.html index bea9586448..39a51da616 100644 --- a/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/delay.html +++ b/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/delay.html @@ -1,54 +1 @@ - - - - - delay - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

delay

-
-
suspend fun delay(duration: Duration)

"java.time" adapter method for kotlinx.coroutines.delay.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/index.html b/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/index.html index 02c133fc4c..b190c65942 100644 --- a/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/index.html +++ b/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/index.html @@ -1,150 +1 @@ - - - - - kotlinx.coroutines.time - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Package kotlinx.coroutines.time

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T> Flow<T>.debounce(timeout: Duration): Flow<T>

"java.time" adapter method for kotlinx.coroutines.flow.debounce.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun delay(duration: Duration)

"java.time" adapter method for kotlinx.coroutines.delay.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <R> SelectBuilder<R>.onTimeout(duration: Duration, block: suspend () -> R)

"java.time" adapter method for SelectBuilder.onTimeout.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T> Flow<T>.sample(period: Duration): Flow<T>

"java.time" adapter method for kotlinx.coroutines.flow.sample.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> withTimeout(duration: Duration, block: suspend CoroutineScope.() -> T): T

"java.time" adapter method for kotlinx.coroutines.withTimeout.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> withTimeoutOrNull(duration: Duration, block: suspend CoroutineScope.() -> T): T?

"java.time" adapter method for kotlinx.coroutines.withTimeoutOrNull.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/on-timeout.html b/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/on-timeout.html index a24f9b4af1..7fb842f32b 100644 --- a/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/on-timeout.html +++ b/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/on-timeout.html @@ -1,54 +1 @@ - - - - - onTimeout - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

onTimeout

-
-
fun <R> SelectBuilder<R>.onTimeout(duration: Duration, block: suspend () -> R)

"java.time" adapter method for SelectBuilder.onTimeout.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/sample.html b/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/sample.html index a575806553..5e80705b0d 100644 --- a/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/sample.html +++ b/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/sample.html @@ -1,54 +1 @@ - - - - - sample - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

sample

-
-
fun <T> Flow<T>.sample(period: Duration): Flow<T>

"java.time" adapter method for kotlinx.coroutines.flow.sample.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/with-timeout-or-null.html b/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/with-timeout-or-null.html index 0449465698..3ee6604ec1 100644 --- a/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/with-timeout-or-null.html +++ b/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/with-timeout-or-null.html @@ -1,54 +1 @@ - - - - - withTimeoutOrNull - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

withTimeoutOrNull

-
-
suspend fun <T> withTimeoutOrNull(duration: Duration, block: suspend CoroutineScope.() -> T): T?

"java.time" adapter method for kotlinx.coroutines.withTimeoutOrNull.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/with-timeout.html b/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/with-timeout.html index 824f5e6952..4143144b74 100644 --- a/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/with-timeout.html +++ b/kotlinx-coroutines-jdk8/kotlinx.coroutines.time/with-timeout.html @@ -1,54 +1 @@ - - - - - withTimeout - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

withTimeout

-
-
suspend fun <T> withTimeout(duration: Duration, block: suspend CoroutineScope.() -> T): T

"java.time" adapter method for kotlinx.coroutines.withTimeout.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk8/navigation.html b/kotlinx-coroutines-jdk8/navigation.html deleted file mode 100644 index be03fe14df..0000000000 --- a/kotlinx-coroutines-jdk8/navigation.html +++ /dev/null @@ -1,2047 +0,0 @@ -
- -
- -
- - - -
- -
-
- -
-
- -
-
-
- async() -
-
-
-
- await() -
-
-
- -
- - -
-
- cancel() -
-
-
- -
- - - - - - - - -
- -
-
- -
- - - - - -
- -
-
- -
- - -
- -
-
- ATOMIC -
-
-
-
- DEFAULT -
-
-
-
- LAZY -
-
-
- -
-
- - - - - -
-
- Deferred -
-
-
-
- delay() -
-
- -
- -
- -
- -
-
- -
- - -
- -
-
- -
- - -
-
- invoke() -
-
- -
-
- isActive -
-
-
- -
-
-
- Job -
-
-
-
- job -
-
-
-
- Job() -
-
-
-
- joinAll() -
-
-
-
- launch() -
-
- -
- -
- - - -
- -
- -
-
- plus() -
-
-
-
- promise() -
-
-
- -
- -
-
- Runnable -
-
-
- -
-
- -
- - - - -
- -
-
- -
- -
-
- yield() -
-
-
-
- -
-
- actor() -
-
-
- -
-
- -
-
- -
- - -
- -
- -
-
- -
-
-
- SUSPEND -
-
-
-
-
- Channel -
-
-
-
- Channel() -
-
-
- -
-
- -
- - - -
-
- consume() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- produce() -
-
-
- -
-
- -
-
- -
-
-
- ticker() -
-
-
- -
- -
-
- -
-
-
-
- toList() -
-
- -
-
- -
- -
-
-
- asFlow() -
-
-
- -
-
- -
-
-
- buffer() -
-
-
- -
-
- -
-
-
- catch() -
-
-
- -
-
-
- collect() -
-
- -
- -
-
-
- combine() -
-
- -
- -
-
- -
-
-
- count() -
-
-
- -
- - - - -
-
- drop() -
-
-
- -
-
-
- emitAll() -
-
-
- -
-
-
- filter() -
-
- -
- -
-
- -
-
-
- first() -
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
- Flow -
-
-
-
- flow() -
-
-
- -
-
-
- flowOf() -
-
-
-
- flowOn() -
-
-
-
- fold() -
-
-
- -
-
-
- last() -
-
-
- -
-
- -
-
-
- map() -
-
-
- -
-
- -
-
-
- merge() -
-
- - - - -
- -
-
-
- onEach() -
-
-
-
- onEmpty() -
-
-
-
- onStart() -
-
- -
- -
-
- -
-
-
- reduce() -
-
-
-
- retry() -
-
-
- -
-
- -
-
- -
-
-
- sample() -
-
-
-
- scan() -
-
-
- -
-
-
- shareIn() -
-
-
- -
-
- START -
-
-
-
- STOP -
-
- -
-
- -
-
-
- single() -
-
-
- -
-
-
- StateFlow -
-
-
-
- stateIn() -
-
-
-
- take() -
-
-
- -
-
- -
-
-
- toList() -
-
-
-
- toSet() -
-
-
- -
- - -
-
- update() -
-
-
- -
- -
- -
-
-
- zip() -
-
-
- -
- -
- -
-
-
- select() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- -
-
- Mutex -
-
-
-
- Mutex() -
-
-
-
- Semaphore -
-
-
- -
-
- -
-
- -
-
-
- -
- -
- -
- -
- -
-
- await() -
-
-
-
- future() -
-
-
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
-
- JavaFx -
-
- -
-
-
- -
- - -
- -
-
-
- await() -
-
-
-
- future() -
-
-
- -
- -
- -
-
-
- delay() -
-
-
- -
-
-
- sample() -
-
-
- -
- -
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
- -
-
-
- -
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
-
- publish() -
-
-
-
- -
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
-
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
- - - -
diff --git a/kotlinx-coroutines-jdk9/index.html b/kotlinx-coroutines-jdk9/index.html index 9bc0d244e5..e430fcc467 100644 --- a/kotlinx-coroutines-jdk9/index.html +++ b/kotlinx-coroutines-jdk9/index.html @@ -1,72 +1 @@ - - - - - kotlinx-coroutines-jdk9 - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

kotlinx-coroutines-jdk9

-

Utilities for Java Flow.

Implemented as a collection of thin wrappers over ../kotlinx-coroutines-reactive, an equivalent package for the Reactive Streams.

-
-

Packages

-
-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-

Utilities for Java Flow.

-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/as-flow.html b/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/as-flow.html index 093493e025..1b7def52c3 100644 --- a/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/as-flow.html +++ b/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/as-flow.html @@ -1,54 +1 @@ - - - - - asFlow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asFlow

-
-
fun <T : Any> Flow.Publisher<T>.asFlow(): Flow<T>

Transforms the given reactive Flow Publisher into Flow. Use the buffer operator on the resulting flow to specify the size of the back-pressure. In effect, it specifies the value of the subscription's request. The default buffer capacity for a suspending channel is used by default.

If any of the resulting flow transformations fails, the subscription is immediately cancelled and all the in-flight elements are discarded.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/as-publisher.html b/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/as-publisher.html index b2ba9fc982..343cbf2e0d 100644 --- a/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/as-publisher.html +++ b/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/as-publisher.html @@ -1,54 +1 @@ - - - - - asPublisher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asPublisher

-
-
fun <T : Any> Flow<T>.asPublisher(context: CoroutineContext = EmptyCoroutineContext): Flow.Publisher<T>

Transforms the given flow into a reactive specification compliant Flow Publisher.

An optional context can be specified to control the execution context of calls to the Flow Subscriber methods. A CoroutineDispatcher can be set to confine them to a specific thread; various ThreadContextElement can be set to inject additional context into the caller thread. By default, the Unconfined dispatcher is used, so calls are performed from an arbitrary thread.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/await-first-or-default.html b/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/await-first-or-default.html index 9e20b253fa..a71f19abaa 100644 --- a/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/await-first-or-default.html +++ b/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/await-first-or-default.html @@ -1,54 +1 @@ - - - - - awaitFirstOrDefault - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitFirstOrDefault

-
-
suspend fun <T> Flow.Publisher<T>.awaitFirstOrDefault(default: T): T

Awaits the first value from the given publisher, or returns the default value if none is emitted, without blocking the thread, and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately cancels its Flow.Subscription and resumes with CancellationException.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/await-first-or-else.html b/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/await-first-or-else.html index 1a0ea4256f..06fa71ab19 100644 --- a/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/await-first-or-else.html +++ b/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/await-first-or-else.html @@ -1,54 +1 @@ - - - - - awaitFirstOrElse - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitFirstOrElse

-
-
suspend fun <T> Flow.Publisher<T>.awaitFirstOrElse(defaultValue: () -> T): T

Awaits the first value from the given publisher, or calls defaultValue to get a value if none is emitted, without blocking the thread, and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately cancels its Flow.Subscription and resumes with CancellationException.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/await-first-or-null.html b/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/await-first-or-null.html index 27c43d6a8f..1c5fa902d2 100644 --- a/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/await-first-or-null.html +++ b/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/await-first-or-null.html @@ -1,54 +1 @@ - - - - - awaitFirstOrNull - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitFirstOrNull

-
-
suspend fun <T> Flow.Publisher<T>.awaitFirstOrNull(): T?

Awaits the first value from the given publisher, or returns null if none is emitted, without blocking the thread, and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately cancels its Flow.Subscription and resumes with CancellationException.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/await-first.html b/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/await-first.html index c039050adc..dd3e31558f 100644 --- a/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/await-first.html +++ b/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/await-first.html @@ -1,54 +1 @@ - - - - - awaitFirst - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitFirst

-
-
suspend fun <T> Flow.Publisher<T>.awaitFirst(): T

Awaits the first value from the given publisher without blocking the thread and returns the resulting value, or, if the publisher has produced an error, throws the corresponding exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately cancels its Flow.Subscription and resumes with CancellationException.

Throws

if the publisher does not emit any value

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/await-last.html b/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/await-last.html index 36d73d7be5..ebb670fd71 100644 --- a/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/await-last.html +++ b/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/await-last.html @@ -1,54 +1 @@ - - - - - awaitLast - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitLast

-
-
suspend fun <T> Flow.Publisher<T>.awaitLast(): T

Awaits the last value from the given publisher without blocking the thread and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately cancels its Flow.Subscription and resumes with CancellationException.

Throws

if the publisher does not emit any value

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/await-single.html b/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/await-single.html index 4f98dc4dac..2a239140f3 100644 --- a/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/await-single.html +++ b/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/await-single.html @@ -1,54 +1 @@ - - - - - awaitSingle - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitSingle

-
-
suspend fun <T> Flow.Publisher<T>.awaitSingle(): T

Awaits the single value from the given publisher without blocking the thread and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately cancels its Flow.Subscription and resumes with CancellationException.

Throws

if the publisher does not emit any value

if the publisher emits more than one value

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/collect.html b/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/collect.html index fef1aac5b6..47d7fcae35 100644 --- a/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/collect.html +++ b/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/collect.html @@ -1,54 +1 @@ - - - - - collect - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

collect

-
-
inline suspend fun <T> Flow.Publisher<T>.collect(action: (T) -> Unit)

Subscribes to this Flow Publisher and performs the specified action for each received element.

If action throws an exception at some point, the subscription is cancelled, and the exception is rethrown from collect. Also, if the publisher signals an error, that error is rethrown from collect.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/flow-publish.html b/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/flow-publish.html index 54b4575aad..1c6af7f185 100644 --- a/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/flow-publish.html +++ b/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/flow-publish.html @@ -1,54 +1 @@ - - - - - flowPublish - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

flowPublish

-
-
fun <T> flowPublish(context: CoroutineContext = EmptyCoroutineContext, block: suspend ProducerScope<T>.() -> Unit): Flow.Publisher<T>

Creates a cold reactive Flow.Publisher that runs a given block in a coroutine.

Every time the returned flux is subscribed, it starts a new coroutine in the specified context. The coroutine emits (via Flow.Subscriber.onNext) values with send, completes (via Flow.Subscriber.onComplete) when the coroutine completes or channel is explicitly closed, and emits errors (via Flow.Subscriber.onError) if the coroutine throws an exception or closes channel with a cause. Unsubscribing cancels the running coroutine.

Invocations of send are suspended appropriately when subscribers apply back-pressure and to ensure that onNext is not invoked concurrently.

Coroutine context can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used.

Note: This is an experimental api. Behaviour of publishers that work as children in a parent scope with respect to cancellation and error handling may change in the future.

Throws

if the provided context contains a Job instance.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/index.html b/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/index.html index 4bd3712fad..95100369dc 100644 --- a/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/index.html +++ b/kotlinx-coroutines-jdk9/kotlinx.coroutines.jdk9/index.html @@ -1,211 +1 @@ - - - - - kotlinx.coroutines.jdk9 - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Package kotlinx.coroutines.jdk9

-

Utilities for Java Flow.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T : Any> Flow.Publisher<T>.asFlow(): Flow<T>

Transforms the given reactive Flow Publisher into Flow. Use the buffer operator on the resulting flow to specify the size of the back-pressure. In effect, it specifies the value of the subscription's request. The default buffer capacity for a suspending channel is used by default.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T : Any> Flow<T>.asPublisher(context: CoroutineContext = EmptyCoroutineContext): Flow.Publisher<T>

Transforms the given flow into a reactive specification compliant Flow Publisher.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> Flow.Publisher<T>.awaitFirst(): T

Awaits the first value from the given publisher without blocking the thread and returns the resulting value, or, if the publisher has produced an error, throws the corresponding exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> Flow.Publisher<T>.awaitFirstOrDefault(default: T): T

Awaits the first value from the given publisher, or returns the default value if none is emitted, without blocking the thread, and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> Flow.Publisher<T>.awaitFirstOrElse(defaultValue: () -> T): T

Awaits the first value from the given publisher, or calls defaultValue to get a value if none is emitted, without blocking the thread, and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> Flow.Publisher<T>.awaitFirstOrNull(): T?

Awaits the first value from the given publisher, or returns null if none is emitted, without blocking the thread, and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> Flow.Publisher<T>.awaitLast(): T

Awaits the last value from the given publisher without blocking the thread and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> Flow.Publisher<T>.awaitSingle(): T

Awaits the single value from the given publisher without blocking the thread and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
inline suspend fun <T> Flow.Publisher<T>.collect(action: (T) -> Unit)

Subscribes to this Flow Publisher and performs the specified action for each received element.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T> flowPublish(context: CoroutineContext = EmptyCoroutineContext, block: suspend ProducerScope<T>.() -> Unit): Flow.Publisher<T>

Creates a cold reactive Flow.Publisher that runs a given block in a coroutine.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-jdk9/navigation.html b/kotlinx-coroutines-jdk9/navigation.html deleted file mode 100644 index be03fe14df..0000000000 --- a/kotlinx-coroutines-jdk9/navigation.html +++ /dev/null @@ -1,2047 +0,0 @@ -
- -
- -
- - - -
- -
-
- -
-
- -
-
-
- async() -
-
-
-
- await() -
-
-
- -
- - -
-
- cancel() -
-
-
- -
- - - - - - - - -
- -
-
- -
- - - - - -
- -
-
- -
- - -
- -
-
- ATOMIC -
-
-
-
- DEFAULT -
-
-
-
- LAZY -
-
-
- -
-
- - - - - -
-
- Deferred -
-
-
-
- delay() -
-
- -
- -
- -
- -
-
- -
- - -
- -
-
- -
- - -
-
- invoke() -
-
- -
-
- isActive -
-
-
- -
-
-
- Job -
-
-
-
- job -
-
-
-
- Job() -
-
-
-
- joinAll() -
-
-
-
- launch() -
-
- -
- -
- - - -
- -
- -
-
- plus() -
-
-
-
- promise() -
-
-
- -
- -
-
- Runnable -
-
-
- -
-
- -
- - - - -
- -
-
- -
- -
-
- yield() -
-
-
-
- -
-
- actor() -
-
-
- -
-
- -
-
- -
- - -
- -
- -
-
- -
-
-
- SUSPEND -
-
-
-
-
- Channel -
-
-
-
- Channel() -
-
-
- -
-
- -
- - - -
-
- consume() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- produce() -
-
-
- -
-
- -
-
- -
-
-
- ticker() -
-
-
- -
- -
-
- -
-
-
-
- toList() -
-
- -
-
- -
- -
-
-
- asFlow() -
-
-
- -
-
- -
-
-
- buffer() -
-
-
- -
-
- -
-
-
- catch() -
-
-
- -
-
-
- collect() -
-
- -
- -
-
-
- combine() -
-
- -
- -
-
- -
-
-
- count() -
-
-
- -
- - - - -
-
- drop() -
-
-
- -
-
-
- emitAll() -
-
-
- -
-
-
- filter() -
-
- -
- -
-
- -
-
-
- first() -
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
- Flow -
-
-
-
- flow() -
-
-
- -
-
-
- flowOf() -
-
-
-
- flowOn() -
-
-
-
- fold() -
-
-
- -
-
-
- last() -
-
-
- -
-
- -
-
-
- map() -
-
-
- -
-
- -
-
-
- merge() -
-
- - - - -
- -
-
-
- onEach() -
-
-
-
- onEmpty() -
-
-
-
- onStart() -
-
- -
- -
-
- -
-
-
- reduce() -
-
-
-
- retry() -
-
-
- -
-
- -
-
- -
-
-
- sample() -
-
-
-
- scan() -
-
-
- -
-
-
- shareIn() -
-
-
- -
-
- START -
-
-
-
- STOP -
-
- -
-
- -
-
-
- single() -
-
-
- -
-
-
- StateFlow -
-
-
-
- stateIn() -
-
-
-
- take() -
-
-
- -
-
- -
-
-
- toList() -
-
-
-
- toSet() -
-
-
- -
- - -
-
- update() -
-
-
- -
- -
- -
-
-
- zip() -
-
-
- -
- -
- -
-
-
- select() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- -
-
- Mutex -
-
-
-
- Mutex() -
-
-
-
- Semaphore -
-
-
- -
-
- -
-
- -
-
-
- -
- -
- -
- -
- -
-
- await() -
-
-
-
- future() -
-
-
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
-
- JavaFx -
-
- -
-
-
- -
- - -
- -
-
-
- await() -
-
-
-
- future() -
-
-
- -
- -
- -
-
-
- delay() -
-
-
- -
-
-
- sample() -
-
-
- -
- -
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
- -
-
-
- -
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
-
- publish() -
-
-
-
- -
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
-
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
- - - -
diff --git a/kotlinx-coroutines-play-services/index.html b/kotlinx-coroutines-play-services/index.html index c54bddc591..36102d3abd 100644 --- a/kotlinx-coroutines-play-services/index.html +++ b/kotlinx-coroutines-play-services/index.html @@ -1,70 +1 @@ - - - - - kotlinx-coroutines-play-services - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

kotlinx-coroutines-play-services

-

Integration with Google Play Services Tasks API.

Extension functions:

NameDescription
Task.asDeferredConverts a Task into a Deferred
Task.awaitAwaits for completion of the Task (cancellable)
Deferred.asTaskConverts a deferred value to a Task

Example

Using Firebase APIs becomes simple:

FirebaseAuth.getInstance().signInAnonymously().await()
val snapshot = try {
FirebaseFirestore.getInstance().document("users/$id").get().await() // Cancellable await
} catch (e: FirebaseFirestoreException) {
// Handle exception
return@async
}

// Do stuff

If the Task supports cancellation via passing a CancellationToken, pass the corresponding CancellationTokenSource to asDeferred or await to support bi-directional cancellation:

val cancellationTokenSource = CancellationTokenSource()
val currentLocationTask = fusedLocationProviderClient.getCurrentLocation(PRIORITY_HIGH_ACCURACY, cancellationTokenSource.token)
val currentLocation = currentLocationTask.await(cancellationTokenSource) // cancelling `await` also cancels `currentLocationTask`, and vice versa
-
-

Packages

-
-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-play-services/kotlinx.coroutines.tasks/as-deferred.html b/kotlinx-coroutines-play-services/kotlinx.coroutines.tasks/as-deferred.html index 0cf40dad66..4c93998a4d 100644 --- a/kotlinx-coroutines-play-services/kotlinx.coroutines.tasks/as-deferred.html +++ b/kotlinx-coroutines-play-services/kotlinx.coroutines.tasks/as-deferred.html @@ -1,54 +1 @@ - - - - - asDeferred - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asDeferred

-
-
fun <T> Task<T>.asDeferred(): Deferred<T>

Converts this task to an instance of Deferred. If task is cancelled then resulting deferred will be cancelled as well. However, the opposite is not true: if the deferred is cancelled, the Task will not be cancelled. For bi-directional cancellation, an overload that accepts CancellationTokenSource can be used.


fun <T> Task<T>.asDeferred(cancellationTokenSource: CancellationTokenSource): Deferred<T>

Converts this task to an instance of Deferred with a CancellationTokenSource to control cancellation. The cancellation of this function is bi-directional:

  • If the given task is cancelled, the resulting deferred will be cancelled.

  • If the resulting deferred is cancelled, the provided cancellationTokenSource will be cancelled.

Providing a CancellationTokenSource that is unrelated to the receiving Task is not supported and leads to an unspecified behaviour.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-play-services/kotlinx.coroutines.tasks/as-task.html b/kotlinx-coroutines-play-services/kotlinx.coroutines.tasks/as-task.html index a58dc85122..0357d4b542 100644 --- a/kotlinx-coroutines-play-services/kotlinx.coroutines.tasks/as-task.html +++ b/kotlinx-coroutines-play-services/kotlinx.coroutines.tasks/as-task.html @@ -1,54 +1 @@ - - - - - asTask - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asTask

-
-
fun <T> Deferred<T>.asTask(): Task<T>

Converts this deferred to the instance of Task. If deferred is cancelled then resulting task will be cancelled as well.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-play-services/kotlinx.coroutines.tasks/await.html b/kotlinx-coroutines-play-services/kotlinx.coroutines.tasks/await.html index 60590c6227..6581b64542 100644 --- a/kotlinx-coroutines-play-services/kotlinx.coroutines.tasks/await.html +++ b/kotlinx-coroutines-play-services/kotlinx.coroutines.tasks/await.html @@ -1,54 +1 @@ - - - - - await - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

await

-
-
suspend fun <T> Task<T>.await(): T

Awaits the completion of the task without blocking a thread.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this suspending function is waiting, this function stops waiting for the completion stage and immediately resumes with CancellationException.

For bi-directional cancellation, an overload that accepts CancellationTokenSource can be used.


suspend fun <T> Task<T>.await(cancellationTokenSource: CancellationTokenSource): T

Awaits the completion of the task that is linked to the given CancellationTokenSource to control cancellation.

This suspending function is cancellable and cancellation is bi-directional:

Providing a CancellationTokenSource that is unrelated to the receiving Task is not supported and leads to an unspecified behaviour.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-play-services/kotlinx.coroutines.tasks/index.html b/kotlinx-coroutines-play-services/kotlinx.coroutines.tasks/index.html index 39026875a3..b0f0ae1a0f 100644 --- a/kotlinx-coroutines-play-services/kotlinx.coroutines.tasks/index.html +++ b/kotlinx-coroutines-play-services/kotlinx.coroutines.tasks/index.html @@ -1,105 +1 @@ - - - - - kotlinx.coroutines.tasks - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Package kotlinx.coroutines.tasks

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T> Task<T>.asDeferred(): Deferred<T>

Converts this task to an instance of Deferred. If task is cancelled then resulting deferred will be cancelled as well. However, the opposite is not true: if the deferred is cancelled, the Task will not be cancelled. For bi-directional cancellation, an overload that accepts CancellationTokenSource can be used.

fun <T> Task<T>.asDeferred(cancellationTokenSource: CancellationTokenSource): Deferred<T>

Converts this task to an instance of Deferred with a CancellationTokenSource to control cancellation. The cancellation of this function is bi-directional:

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T> Deferred<T>.asTask(): Task<T>

Converts this deferred to the instance of Task. If deferred is cancelled then resulting task will be cancelled as well.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> Task<T>.await(): T

Awaits the completion of the task without blocking a thread.

suspend fun <T> Task<T>.await(cancellationTokenSource: CancellationTokenSource): T

Awaits the completion of the task that is linked to the given CancellationTokenSource to control cancellation.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-play-services/navigation.html b/kotlinx-coroutines-play-services/navigation.html deleted file mode 100644 index be03fe14df..0000000000 --- a/kotlinx-coroutines-play-services/navigation.html +++ /dev/null @@ -1,2047 +0,0 @@ -
- -
- -
- - - -
- -
-
- -
-
- -
-
-
- async() -
-
-
-
- await() -
-
-
- -
- - -
-
- cancel() -
-
-
- -
- - - - - - - - -
- -
-
- -
- - - - - -
- -
-
- -
- - -
- -
-
- ATOMIC -
-
-
-
- DEFAULT -
-
-
-
- LAZY -
-
-
- -
-
- - - - - -
-
- Deferred -
-
-
-
- delay() -
-
- -
- -
- -
- -
-
- -
- - -
- -
-
- -
- - -
-
- invoke() -
-
- -
-
- isActive -
-
-
- -
-
-
- Job -
-
-
-
- job -
-
-
-
- Job() -
-
-
-
- joinAll() -
-
-
-
- launch() -
-
- -
- -
- - - -
- -
- -
-
- plus() -
-
-
-
- promise() -
-
-
- -
- -
-
- Runnable -
-
-
- -
-
- -
- - - - -
- -
-
- -
- -
-
- yield() -
-
-
-
- -
-
- actor() -
-
-
- -
-
- -
-
- -
- - -
- -
- -
-
- -
-
-
- SUSPEND -
-
-
-
-
- Channel -
-
-
-
- Channel() -
-
-
- -
-
- -
- - - -
-
- consume() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- produce() -
-
-
- -
-
- -
-
- -
-
-
- ticker() -
-
-
- -
- -
-
- -
-
-
-
- toList() -
-
- -
-
- -
- -
-
-
- asFlow() -
-
-
- -
-
- -
-
-
- buffer() -
-
-
- -
-
- -
-
-
- catch() -
-
-
- -
-
-
- collect() -
-
- -
- -
-
-
- combine() -
-
- -
- -
-
- -
-
-
- count() -
-
-
- -
- - - - -
-
- drop() -
-
-
- -
-
-
- emitAll() -
-
-
- -
-
-
- filter() -
-
- -
- -
-
- -
-
-
- first() -
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
- Flow -
-
-
-
- flow() -
-
-
- -
-
-
- flowOf() -
-
-
-
- flowOn() -
-
-
-
- fold() -
-
-
- -
-
-
- last() -
-
-
- -
-
- -
-
-
- map() -
-
-
- -
-
- -
-
-
- merge() -
-
- - - - -
- -
-
-
- onEach() -
-
-
-
- onEmpty() -
-
-
-
- onStart() -
-
- -
- -
-
- -
-
-
- reduce() -
-
-
-
- retry() -
-
-
- -
-
- -
-
- -
-
-
- sample() -
-
-
-
- scan() -
-
-
- -
-
-
- shareIn() -
-
-
- -
-
- START -
-
-
-
- STOP -
-
- -
-
- -
-
-
- single() -
-
-
- -
-
-
- StateFlow -
-
-
-
- stateIn() -
-
-
-
- take() -
-
-
- -
-
- -
-
-
- toList() -
-
-
-
- toSet() -
-
-
- -
- - -
-
- update() -
-
-
- -
- -
- -
-
-
- zip() -
-
-
- -
- -
- -
-
-
- select() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- -
-
- Mutex -
-
-
-
- Mutex() -
-
-
-
- Semaphore -
-
-
- -
-
- -
-
- -
-
-
- -
- -
- -
- -
- -
-
- await() -
-
-
-
- future() -
-
-
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
-
- JavaFx -
-
- -
-
-
- -
- - -
- -
-
-
- await() -
-
-
-
- future() -
-
-
- -
- -
- -
-
-
- delay() -
-
-
- -
-
-
- sample() -
-
-
- -
- -
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
- -
-
-
- -
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
-
- publish() -
-
-
-
- -
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
-
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
- - - -
diff --git a/kotlinx-coroutines-reactive/index.html b/kotlinx-coroutines-reactive/index.html index f49b1017df..a15f1b56f7 100644 --- a/kotlinx-coroutines-reactive/index.html +++ b/kotlinx-coroutines-reactive/index.html @@ -1,72 +1 @@ - - - - - kotlinx-coroutines-reactive - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

kotlinx-coroutines-reactive

-

Utilities for Reactive Streams.

Coroutine builders:

NameResultScopeDescription
kotlinx.coroutines.reactive.publishPublisherProducerScopeCold reactive publisher that starts the coroutine on subscribe

Integration with Flow:

NameResultDescription
Publisher.asFlowFlowConverts the given publisher to a flow
Flow.asPublisherPublisherConverts the given flow to a TCK-compliant publisher

If these adapters are used along with kotlinx-coroutines-reactor in the classpath, then Reactor's Context is properly propagated as coroutine context element (ReactorContext) and vice versa.

Suspending extension functions and suspending iteration:

NameDescription
Publisher.awaitFirstReturns the first value from the given publisher
Publisher.awaitFirstOrDefaultReturns the first value from the given publisher or default
Publisher.awaitFirstOrElseReturns the first value from the given publisher or default from a function
Publisher.awaitFirstOrNullReturns the first value from the given publisher or null
Publisher.awaitLastReturns the last value from the given publisher
Publisher.awaitSingleReturns the single value from the given publisher
-
-

Packages

-
-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-

Utilities for Reactive Streams.

-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/as-flow.html b/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/as-flow.html index cc1144e32f..4404c72735 100644 --- a/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/as-flow.html +++ b/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/as-flow.html @@ -1,54 +1 @@ - - - - - asFlow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asFlow

-
-
fun <T : Any> Publisher<T>.asFlow(): Flow<T>

Transforms the given reactive Publisher into Flow. Use the buffer operator on the resulting flow to specify the size of the back-pressure. In effect, it specifies the value of the subscription's request. The default buffer capacity for a suspending channel is used by default.

If any of the resulting flow transformations fails, the subscription is immediately cancelled and all the in-flight elements are discarded.

This function is integrated with ReactorContext from kotlinx-coroutines-reactor module, see its documentation for additional details.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/as-publisher.html b/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/as-publisher.html index 681eeb9ea6..590af4cd39 100644 --- a/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/as-publisher.html +++ b/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/as-publisher.html @@ -1,54 +1 @@ - - - - - asPublisher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asPublisher

-
-
fun <T : Any> Flow<T>.asPublisher(context: CoroutineContext = EmptyCoroutineContext): Publisher<T>

Transforms the given flow into a reactive specification compliant Publisher.

This function is integrated with ReactorContext from kotlinx-coroutines-reactor module, see its documentation for additional details.

An optional context can be specified to control the execution context of calls to the Subscriber methods. A CoroutineDispatcher can be set to confine them to a specific thread; various ThreadContextElement can be set to inject additional context into the caller thread. By default, the Unconfined dispatcher is used, so calls are performed from an arbitrary thread.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/await-first-or-default.html b/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/await-first-or-default.html index c3c08fa59a..a1643aeaea 100644 --- a/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/await-first-or-default.html +++ b/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/await-first-or-default.html @@ -1,54 +1 @@ - - - - - awaitFirstOrDefault - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitFirstOrDefault

-
-
suspend fun <T> Publisher<T>.awaitFirstOrDefault(default: T): T

Awaits the first value from the given publisher, or returns the default value if none is emitted, without blocking the thread, and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately cancels its Subscription and resumes with CancellationException.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/await-first-or-else.html b/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/await-first-or-else.html index fa1a88a114..272cfb3ed6 100644 --- a/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/await-first-or-else.html +++ b/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/await-first-or-else.html @@ -1,54 +1 @@ - - - - - awaitFirstOrElse - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitFirstOrElse

-
-
suspend fun <T> Publisher<T>.awaitFirstOrElse(defaultValue: () -> T): T

Awaits the first value from the given publisher, or calls defaultValue to get a value if none is emitted, without blocking the thread, and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately cancels its Subscription and resumes with CancellationException.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/await-first-or-null.html b/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/await-first-or-null.html index ea17b6f984..6e866590e6 100644 --- a/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/await-first-or-null.html +++ b/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/await-first-or-null.html @@ -1,54 +1 @@ - - - - - awaitFirstOrNull - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitFirstOrNull

-
-
suspend fun <T> Publisher<T>.awaitFirstOrNull(): T?

Awaits the first value from the given publisher, or returns null if none is emitted, without blocking the thread, and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately cancels its Subscription and resumes with CancellationException.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/await-first.html b/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/await-first.html index 4abc9d43b4..ebdb22c7b6 100644 --- a/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/await-first.html +++ b/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/await-first.html @@ -1,54 +1 @@ - - - - - awaitFirst - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitFirst

-
-
suspend fun <T> Publisher<T>.awaitFirst(): T

Awaits the first value from the given publisher without blocking the thread and returns the resulting value, or, if the publisher has produced an error, throws the corresponding exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately cancels its Subscription and resumes with CancellationException.

Throws

if the publisher does not emit any value

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/await-last.html b/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/await-last.html index ac5f9d0e73..ec2052903d 100644 --- a/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/await-last.html +++ b/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/await-last.html @@ -1,54 +1 @@ - - - - - awaitLast - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitLast

-
-
suspend fun <T> Publisher<T>.awaitLast(): T

Awaits the last value from the given publisher without blocking the thread and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately cancels its Subscription and resumes with CancellationException.

Throws

if the publisher does not emit any value

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/await-single.html b/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/await-single.html index 0b226b2fad..a50f85d805 100644 --- a/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/await-single.html +++ b/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/await-single.html @@ -1,54 +1 @@ - - - - - awaitSingle - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitSingle

-
-
suspend fun <T> Publisher<T>.awaitSingle(): T

Awaits the single value from the given publisher without blocking the thread and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately cancels its Subscription and resumes with CancellationException.

Throws

if the publisher does not emit any value

if the publisher emits more than one value

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/collect.html b/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/collect.html index d49d02fbab..17a1a6c0bd 100644 --- a/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/collect.html +++ b/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/collect.html @@ -1,54 +1 @@ - - - - - collect - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

collect

-
-
inline suspend fun <T> Publisher<T>.collect(action: (T) -> Unit)

Subscribes to this Publisher and performs the specified action for each received element.

If action throws an exception at some point, the subscription is cancelled, and the exception is rethrown from collect. Also, if the publisher signals an error, that error is rethrown from collect.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/index.html b/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/index.html index 9d0d6343b4..c03cd04dc0 100644 --- a/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/index.html +++ b/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/index.html @@ -1,211 +1 @@ - - - - - kotlinx.coroutines.reactive - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Package kotlinx.coroutines.reactive

-

Utilities for Reactive Streams.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T : Any> Publisher<T>.asFlow(): Flow<T>

Transforms the given reactive Publisher into Flow. Use the buffer operator on the resulting flow to specify the size of the back-pressure. In effect, it specifies the value of the subscription's request. The default buffer capacity for a suspending channel is used by default.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T : Any> Flow<T>.asPublisher(context: CoroutineContext = EmptyCoroutineContext): Publisher<T>

Transforms the given flow into a reactive specification compliant Publisher.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> Publisher<T>.awaitFirst(): T

Awaits the first value from the given publisher without blocking the thread and returns the resulting value, or, if the publisher has produced an error, throws the corresponding exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> Publisher<T>.awaitFirstOrDefault(default: T): T

Awaits the first value from the given publisher, or returns the default value if none is emitted, without blocking the thread, and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> Publisher<T>.awaitFirstOrElse(defaultValue: () -> T): T

Awaits the first value from the given publisher, or calls defaultValue to get a value if none is emitted, without blocking the thread, and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> Publisher<T>.awaitFirstOrNull(): T?

Awaits the first value from the given publisher, or returns null if none is emitted, without blocking the thread, and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> Publisher<T>.awaitLast(): T

Awaits the last value from the given publisher without blocking the thread and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> Publisher<T>.awaitSingle(): T

Awaits the single value from the given publisher without blocking the thread and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
inline suspend fun <T> Publisher<T>.collect(action: (T) -> Unit)

Subscribes to this Publisher and performs the specified action for each received element.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T> publish(context: CoroutineContext = EmptyCoroutineContext, block: suspend ProducerScope<T>.() -> Unit): Publisher<T>

Creates a cold reactive Publisher that runs a given block in a coroutine.

fun <T> CoroutineScope.publish(context: CoroutineContext = EmptyCoroutineContext, block: suspend ProducerScope<T>.() -> Unit): Publisher<T>
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/publish.html b/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/publish.html index afb51c5c2e..7ac97b31a1 100644 --- a/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/publish.html +++ b/kotlinx-coroutines-reactive/kotlinx.coroutines.reactive/publish.html @@ -1,54 +1 @@ - - - - - publish - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

publish

-
-
fun <T> publish(context: CoroutineContext = EmptyCoroutineContext, block: suspend ProducerScope<T>.() -> Unit): Publisher<T>

Creates a cold reactive Publisher that runs a given block in a coroutine.

Every time the returned flux is subscribed, it starts a new coroutine in the specified context. The coroutine emits (via Subscriber.onNext) values with send, completes (via Subscriber.onComplete) when the coroutine completes or channel is explicitly closed, and emits errors (via Subscriber.onError) if the coroutine throws an exception or closes channel with a cause. Unsubscribing cancels the running coroutine.

Invocations of send are suspended appropriately when subscribers apply back-pressure and to ensure that onNext is not invoked concurrently.

Coroutine context can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used.

Note: This is an experimental api. Behaviour of publishers that work as children in a parent scope with respect to cancellation and error handling may change in the future.

Throws

if the provided context contains a Job instance.


fun <T> CoroutineScope.publish(context: CoroutineContext = EmptyCoroutineContext, block: suspend ProducerScope<T>.() -> Unit): Publisher<T>
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactive/navigation.html b/kotlinx-coroutines-reactive/navigation.html deleted file mode 100644 index be03fe14df..0000000000 --- a/kotlinx-coroutines-reactive/navigation.html +++ /dev/null @@ -1,2047 +0,0 @@ -
- -
- -
- - - -
- -
-
- -
-
- -
-
-
- async() -
-
-
-
- await() -
-
-
- -
- - -
-
- cancel() -
-
-
- -
- - - - - - - - -
- -
-
- -
- - - - - -
- -
-
- -
- - -
- -
-
- ATOMIC -
-
-
-
- DEFAULT -
-
-
-
- LAZY -
-
-
- -
-
- - - - - -
-
- Deferred -
-
-
-
- delay() -
-
- -
- -
- -
- -
-
- -
- - -
- -
-
- -
- - -
-
- invoke() -
-
- -
-
- isActive -
-
-
- -
-
-
- Job -
-
-
-
- job -
-
-
-
- Job() -
-
-
-
- joinAll() -
-
-
-
- launch() -
-
- -
- -
- - - -
- -
- -
-
- plus() -
-
-
-
- promise() -
-
-
- -
- -
-
- Runnable -
-
-
- -
-
- -
- - - - -
- -
-
- -
- -
-
- yield() -
-
-
-
- -
-
- actor() -
-
-
- -
-
- -
-
- -
- - -
- -
- -
-
- -
-
-
- SUSPEND -
-
-
-
-
- Channel -
-
-
-
- Channel() -
-
-
- -
-
- -
- - - -
-
- consume() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- produce() -
-
-
- -
-
- -
-
- -
-
-
- ticker() -
-
-
- -
- -
-
- -
-
-
-
- toList() -
-
- -
-
- -
- -
-
-
- asFlow() -
-
-
- -
-
- -
-
-
- buffer() -
-
-
- -
-
- -
-
-
- catch() -
-
-
- -
-
-
- collect() -
-
- -
- -
-
-
- combine() -
-
- -
- -
-
- -
-
-
- count() -
-
-
- -
- - - - -
-
- drop() -
-
-
- -
-
-
- emitAll() -
-
-
- -
-
-
- filter() -
-
- -
- -
-
- -
-
-
- first() -
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
- Flow -
-
-
-
- flow() -
-
-
- -
-
-
- flowOf() -
-
-
-
- flowOn() -
-
-
-
- fold() -
-
-
- -
-
-
- last() -
-
-
- -
-
- -
-
-
- map() -
-
-
- -
-
- -
-
-
- merge() -
-
- - - - -
- -
-
-
- onEach() -
-
-
-
- onEmpty() -
-
-
-
- onStart() -
-
- -
- -
-
- -
-
-
- reduce() -
-
-
-
- retry() -
-
-
- -
-
- -
-
- -
-
-
- sample() -
-
-
-
- scan() -
-
-
- -
-
-
- shareIn() -
-
-
- -
-
- START -
-
-
-
- STOP -
-
- -
-
- -
-
-
- single() -
-
-
- -
-
-
- StateFlow -
-
-
-
- stateIn() -
-
-
-
- take() -
-
-
- -
-
- -
-
-
- toList() -
-
-
-
- toSet() -
-
-
- -
- - -
-
- update() -
-
-
- -
- -
- -
-
-
- zip() -
-
-
- -
- -
- -
-
-
- select() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- -
-
- Mutex -
-
-
-
- Mutex() -
-
-
-
- Semaphore -
-
-
- -
-
- -
-
- -
-
-
- -
- -
- -
- -
- -
-
- await() -
-
-
-
- future() -
-
-
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
-
- JavaFx -
-
- -
-
-
- -
- - -
- -
-
-
- await() -
-
-
-
- future() -
-
-
- -
- -
- -
-
-
- delay() -
-
-
- -
-
-
- sample() -
-
-
- -
- -
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
- -
-
-
- -
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
-
- publish() -
-
-
-
- -
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
-
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
- - - -
diff --git a/kotlinx-coroutines-reactor/index.html b/kotlinx-coroutines-reactor/index.html index e7ac7c9dea..d141b8197a 100644 --- a/kotlinx-coroutines-reactor/index.html +++ b/kotlinx-coroutines-reactor/index.html @@ -1,72 +1 @@ - - - - - kotlinx-coroutines-reactor - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

kotlinx-coroutines-reactor

-

Utilities for Reactor.

Coroutine builders:

NameResultScopeDescription
monoMonoCoroutineScopeA cold Mono that starts the coroutine on subscription
fluxFluxCoroutineScopeA cold Flux that starts the coroutine on subscription

Note that Mono and Flux are subclasses of Reactive Streams' Publisher and extensions for it are covered by the ../kotlinx-coroutines-reactive module.

Integration with Flow:

NameResultDescription
Flow.asFluxFluxConverts the given flow to a TCK-compliant Flux.

This adapter is integrated with Reactor's Context and coroutines' ReactorContext.

Conversion functions:

NameDescription
Job.asMonoConverts a job to a hot Mono
Deferred.asMonoConverts a deferred value to a hot Mono
Scheduler.asCoroutineDispatcherConverts a scheduler to a CoroutineDispatcher
-
-

Packages

-
-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-

Utilities for Reactor.

-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-reactor-context/-key/index.html b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-reactor-context/-key/index.html index ab2d3a7649..0d1f2bf325 100644 --- a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-reactor-context/-key/index.html +++ b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-reactor-context/-key/index.html @@ -1,58 +1 @@ - - - - - Key - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Key

-
object Key : CoroutineContext.Key<ReactorContext>
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-reactor-context/-reactor-context.html b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-reactor-context/-reactor-context.html index 1f43eade39..6069f80b54 100644 --- a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-reactor-context/-reactor-context.html +++ b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-reactor-context/-reactor-context.html @@ -1,54 +1 @@ - - - - - ReactorContext - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

ReactorContext

-
-
fun ReactorContext(contextView: ContextView)
fun ReactorContext(context: Context)
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-reactor-context/context.html b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-reactor-context/context.html index 9df88ba4a5..8840b87a82 100644 --- a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-reactor-context/context.html +++ b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-reactor-context/context.html @@ -1,54 +1 @@ - - - - - context - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

context

-
-
val context: Context
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-reactor-context/index.html b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-reactor-context/index.html index 3613b217c5..494d759aa3 100644 --- a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-reactor-context/index.html +++ b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-reactor-context/index.html @@ -1,142 +1 @@ - - - - - ReactorContext - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

ReactorContext

-
class ReactorContext(val context: Context) : AbstractCoroutineContextElement

Wraps Reactor's Context into a CoroutineContext element for seamless integration between Reactor and kotlinx.coroutines. Context.asCoroutineContext puts Reactor's Context elements into a CoroutineContext, which can be used to propagate the information about Reactor's Context through coroutines.

This context element is implicitly propagated through subscribers' context by all Reactive integrations, such as mono, flux, Publisher.asFlow, Flow.asPublisher and Flow.asFlux. Functions that subscribe to a reactive stream (e.g. Publisher.awaitFirst), too, propagate ReactorContext to the subscriber's Context.

Examples of Reactive context integration.

Propagating ReactorContext to Reactor's Context

val flux = myDatabaseService.getUsers()
.contextWrite { ctx -> println(ctx); ctx }
flux.awaitFirst() // Will print "null"

// Now add ReactorContext
withContext(Context.of("answer", "42").asCoroutineContext()) {
flux.awaitFirst() // Will print "Context{'key'='value'}"
}

Propagating subscriber's Context to ReactorContext:

val flow = flow {
println("Reactor context in Flow: " + currentCoroutineContext()[ReactorContext])
}
// No context
flow.asFlux()
.subscribe() // Will print 'Reactor context in Flow: null'
// Add subscriber's context
flow.asFlux()
.contextWrite { ctx -> ctx.put("answer", 42) }
.subscribe() // Will print "Reactor context in Flow: Context{'answer'=42}"
-
-
-
-
-

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
fun ReactorContext(contextView: ContextView)
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun ReactorContext(context: Context)
-
-
-
-
-
-

Types

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
object Key : CoroutineContext.Key<ReactorContext>
-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
open override fun toString(): String
-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
val context: Context
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-reactor-context/to-string.html b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-reactor-context/to-string.html index 1a92ffaaec..285f9af98f 100644 --- a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-reactor-context/to-string.html +++ b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-reactor-context/to-string.html @@ -1,54 +1 @@ - - - - - toString - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

toString

-
-
open override fun toString(): String
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-scheduler-coroutine-dispatcher/-scheduler-coroutine-dispatcher.html b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-scheduler-coroutine-dispatcher/-scheduler-coroutine-dispatcher.html index 0b2d354223..18bec35184 100644 --- a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-scheduler-coroutine-dispatcher/-scheduler-coroutine-dispatcher.html +++ b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-scheduler-coroutine-dispatcher/-scheduler-coroutine-dispatcher.html @@ -1,54 +1 @@ - - - - - SchedulerCoroutineDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

SchedulerCoroutineDispatcher

-
-
fun SchedulerCoroutineDispatcher(scheduler: Scheduler)

Parameters

scheduler

a scheduler.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-scheduler-coroutine-dispatcher/index.html b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-scheduler-coroutine-dispatcher/index.html index a7747fdaae..974fc90846 100644 --- a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-scheduler-coroutine-dispatcher/index.html +++ b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-scheduler-coroutine-dispatcher/index.html @@ -1,97 +1 @@ - - - - - SchedulerCoroutineDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

SchedulerCoroutineDispatcher

-
class SchedulerCoroutineDispatcher(val scheduler: Scheduler) : CoroutineDispatcher, Delay

Implements CoroutineDispatcher on top of an arbitrary Scheduler.

-
-
-
-
-

Parameters

-
-
scheduler

a scheduler.

-
-

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
fun SchedulerCoroutineDispatcher(scheduler: Scheduler)
-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
val scheduler: Scheduler

Underlying scheduler of current CoroutineDispatcher.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-scheduler-coroutine-dispatcher/scheduler.html b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-scheduler-coroutine-dispatcher/scheduler.html index b80e33848a..87c137914c 100644 --- a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-scheduler-coroutine-dispatcher/scheduler.html +++ b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/-scheduler-coroutine-dispatcher/scheduler.html @@ -1,54 +1 @@ - - - - - scheduler - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

scheduler

-
-
val scheduler: Scheduler

Underlying scheduler of current CoroutineDispatcher.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/as-coroutine-context.html b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/as-coroutine-context.html index bae0c7084a..196be5a7e9 100644 --- a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/as-coroutine-context.html +++ b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/as-coroutine-context.html @@ -1,54 +1 @@ - - - - - asCoroutineContext - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asCoroutineContext

-
-
fun ContextView.asCoroutineContext(): ReactorContext

Wraps the given ContextView into ReactorContext, so it can be added to the coroutine's context and later used via coroutineContext[ReactorContext].

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/as-coroutine-dispatcher.html b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/as-coroutine-dispatcher.html index 6db20cfa18..1ea013625a 100644 --- a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/as-coroutine-dispatcher.html +++ b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/as-coroutine-dispatcher.html @@ -1,54 +1 @@ - - - - - asCoroutineDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asCoroutineDispatcher

-
-

Converts an instance of Scheduler to an implementation of CoroutineDispatcher.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/as-flux.html b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/as-flux.html index 9f8bd51266..682fcf38f8 100644 --- a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/as-flux.html +++ b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/as-flux.html @@ -1,54 +1 @@ - - - - - asFlux - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asFlux

-
-
fun <T : Any> Flow<T>.asFlux(context: CoroutineContext = EmptyCoroutineContext): Flux<T>

Converts the given flow to a cold flux. The original flow is cancelled when the flux subscriber is disposed.

This function is integrated with ReactorContext, see its documentation for additional details.

An optional context can be specified to control the execution context of calls to Subscriber methods. You can set a CoroutineDispatcher to confine them to a specific thread and/or various ThreadContextElement to inject additional context into the caller thread. By default, the Unconfined dispatcher is used, so calls are performed from an arbitrary thread.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/as-mono.html b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/as-mono.html index 0fb1ef1b1b..d122933c8c 100644 --- a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/as-mono.html +++ b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/as-mono.html @@ -1,54 +1 @@ - - - - - asMono - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asMono

-
-
fun Job.asMono(context: CoroutineContext): Mono<Unit>

Converts this job to the hot reactive mono that signals with success when the corresponding job completes.

Every subscriber gets the signal at the same time. Unsubscribing from the resulting mono does not affect the original job in any way.

Note: This is an experimental api. Conversion of coroutines primitives to reactive entities may change in the future to account for the concept of structured concurrency.

Parameters

context

-- the coroutine context from which the resulting mono is going to be signalled


fun <T> Deferred<T?>.asMono(context: CoroutineContext): Mono<T>

Converts this deferred value to the hot reactive mono that signals success or error.

Every subscriber gets the same completion value. Unsubscribing from the resulting mono does not affect the original deferred value in any way.

Note: This is an experimental api. Conversion of coroutines primitives to reactive entities may change in the future to account for the concept of structured concurrency.

Parameters

context

-- the coroutine context from which the resulting mono is going to be signalled

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/await-single-or-null.html b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/await-single-or-null.html index 388a3f9993..306cdd431c 100644 --- a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/await-single-or-null.html +++ b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/await-single-or-null.html @@ -1,54 +1 @@ - - - - - awaitSingleOrNull - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitSingleOrNull

-
-
suspend fun <T> Mono<T>.awaitSingleOrNull(): T?

Awaits the single value from the given Mono without blocking the thread and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception. If the Mono completed without a value, null is returned.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately cancels its Subscription and resumes with CancellationException.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/await-single.html b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/await-single.html index fc5b860585..109bdf5424 100644 --- a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/await-single.html +++ b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/await-single.html @@ -1,54 +1 @@ - - - - - awaitSingle - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitSingle

-
-
suspend fun <T> Mono<T>.awaitSingle(): T

Awaits the single value from the given Mono without blocking the thread and returns the resulting value, or, if this Mono has produced an error, throws the corresponding exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately cancels its Subscription and resumes with CancellationException.

Throws

if the Mono does not emit any value

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/flux.html b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/flux.html index ea38dadca4..b9707b1885 100644 --- a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/flux.html +++ b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/flux.html @@ -1,54 +1 @@ - - - - - flux - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

flux

-
-
fun <T> flux(context: CoroutineContext = EmptyCoroutineContext, block: suspend ProducerScope<T>.() -> Unit): Flux<T>

Creates a cold reactive Flux that runs the given block in a coroutine. Every time the returned flux is subscribed, it starts a new coroutine in the specified context. The coroutine emits (Subscriber.onNext) values with send, completes (Subscriber.onComplete) when the coroutine completes, or, in case the coroutine throws an exception or the channel is closed, emits the error (Subscriber.onError) and closes the channel with the cause. Unsubscribing cancels the running coroutine.

Invocations of send are suspended appropriately when subscribers apply back-pressure and to ensure that onNext is not invoked concurrently.

Note: This is an experimental api. Behaviour of publishers that work as children in a parent scope with respect to cancellation and error handling may change in the future.

Throws

if the provided context contains a Job instance.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/index.html b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/index.html index ad0a2b2922..2f18030e2e 100644 --- a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/index.html +++ b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/index.html @@ -1,213 +1 @@ - - - - - kotlinx.coroutines.reactor - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Package kotlinx.coroutines.reactor

-

Utilities for Reactor.

-
-
-
-
-

Types

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
class ReactorContext(val context: Context) : AbstractCoroutineContextElement

Wraps Reactor's Context into a CoroutineContext element for seamless integration between Reactor and kotlinx.coroutines. Context.asCoroutineContext puts Reactor's Context elements into a CoroutineContext, which can be used to propagate the information about Reactor's Context through coroutines.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
class SchedulerCoroutineDispatcher(val scheduler: Scheduler) : CoroutineDispatcher, Delay

Implements CoroutineDispatcher on top of an arbitrary Scheduler.

-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
fun ContextView.asCoroutineContext(): ReactorContext

Wraps the given ContextView into ReactorContext, so it can be added to the coroutine's context and later used via coroutineContext[ReactorContext].

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-

Converts an instance of Scheduler to an implementation of CoroutineDispatcher.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T : Any> Flow<T>.asFlux(context: CoroutineContext = EmptyCoroutineContext): Flux<T>

Converts the given flow to a cold flux. The original flow is cancelled when the flux subscriber is disposed.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T> Deferred<T?>.asMono(context: CoroutineContext): Mono<T>

Converts this deferred value to the hot reactive mono that signals success or error.

fun Job.asMono(context: CoroutineContext): Mono<Unit>

Converts this job to the hot reactive mono that signals with success when the corresponding job completes.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> Mono<T>.awaitSingle(): T

Awaits the single value from the given Mono without blocking the thread and returns the resulting value, or, if this Mono has produced an error, throws the corresponding exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> Mono<T>.awaitSingleOrNull(): T?

Awaits the single value from the given Mono without blocking the thread and returns the resulting value, or, if this publisher has produced an error, throws the corresponding exception. If the Mono completed without a value, null is returned.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T> flux(context: CoroutineContext = EmptyCoroutineContext, block: suspend ProducerScope<T>.() -> Unit): Flux<T>

Creates a cold reactive Flux that runs the given block in a coroutine. Every time the returned flux is subscribed, it starts a new coroutine in the specified context. The coroutine emits (Subscriber.onNext) values with send, completes (Subscriber.onComplete) when the coroutine completes, or, in case the coroutine throws an exception or the channel is closed, emits the error (Subscriber.onError) and closes the channel with the cause. Unsubscribing cancels the running coroutine.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T> mono(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T?): Mono<T>

Creates a cold mono that runs a given block in a coroutine and emits its result. Every time the returned mono is subscribed, it starts a new coroutine. If the result of block is null, MonoSink.success is invoked without a value. Unsubscribing cancels the running coroutine.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/mono.html b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/mono.html index 37b5181049..f39ac8f186 100644 --- a/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/mono.html +++ b/kotlinx-coroutines-reactor/kotlinx.coroutines.reactor/mono.html @@ -1,54 +1 @@ - - - - - mono - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

mono

-
-
fun <T> mono(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T?): Mono<T>

Creates a cold mono that runs a given block in a coroutine and emits its result. Every time the returned mono is subscribed, it starts a new coroutine. If the result of block is null, MonoSink.success is invoked without a value. Unsubscribing cancels the running coroutine.

Coroutine context can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used.

Throws

if the provided context contains a Job instance.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-reactor/navigation.html b/kotlinx-coroutines-reactor/navigation.html deleted file mode 100644 index be03fe14df..0000000000 --- a/kotlinx-coroutines-reactor/navigation.html +++ /dev/null @@ -1,2047 +0,0 @@ -
- -
- -
- - - -
- -
-
- -
-
- -
-
-
- async() -
-
-
-
- await() -
-
-
- -
- - -
-
- cancel() -
-
-
- -
- - - - - - - - -
- -
-
- -
- - - - - -
- -
-
- -
- - -
- -
-
- ATOMIC -
-
-
-
- DEFAULT -
-
-
-
- LAZY -
-
-
- -
-
- - - - - -
-
- Deferred -
-
-
-
- delay() -
-
- -
- -
- -
- -
-
- -
- - -
- -
-
- -
- - -
-
- invoke() -
-
- -
-
- isActive -
-
-
- -
-
-
- Job -
-
-
-
- job -
-
-
-
- Job() -
-
-
-
- joinAll() -
-
-
-
- launch() -
-
- -
- -
- - - -
- -
- -
-
- plus() -
-
-
-
- promise() -
-
-
- -
- -
-
- Runnable -
-
-
- -
-
- -
- - - - -
- -
-
- -
- -
-
- yield() -
-
-
-
- -
-
- actor() -
-
-
- -
-
- -
-
- -
- - -
- -
- -
-
- -
-
-
- SUSPEND -
-
-
-
-
- Channel -
-
-
-
- Channel() -
-
-
- -
-
- -
- - - -
-
- consume() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- produce() -
-
-
- -
-
- -
-
- -
-
-
- ticker() -
-
-
- -
- -
-
- -
-
-
-
- toList() -
-
- -
-
- -
- -
-
-
- asFlow() -
-
-
- -
-
- -
-
-
- buffer() -
-
-
- -
-
- -
-
-
- catch() -
-
-
- -
-
-
- collect() -
-
- -
- -
-
-
- combine() -
-
- -
- -
-
- -
-
-
- count() -
-
-
- -
- - - - -
-
- drop() -
-
-
- -
-
-
- emitAll() -
-
-
- -
-
-
- filter() -
-
- -
- -
-
- -
-
-
- first() -
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
- Flow -
-
-
-
- flow() -
-
-
- -
-
-
- flowOf() -
-
-
-
- flowOn() -
-
-
-
- fold() -
-
-
- -
-
-
- last() -
-
-
- -
-
- -
-
-
- map() -
-
-
- -
-
- -
-
-
- merge() -
-
- - - - -
- -
-
-
- onEach() -
-
-
-
- onEmpty() -
-
-
-
- onStart() -
-
- -
- -
-
- -
-
-
- reduce() -
-
-
-
- retry() -
-
-
- -
-
- -
-
- -
-
-
- sample() -
-
-
-
- scan() -
-
-
- -
-
-
- shareIn() -
-
-
- -
-
- START -
-
-
-
- STOP -
-
- -
-
- -
-
-
- single() -
-
-
- -
-
-
- StateFlow -
-
-
-
- stateIn() -
-
-
-
- take() -
-
-
- -
-
- -
-
-
- toList() -
-
-
-
- toSet() -
-
-
- -
- - -
-
- update() -
-
-
- -
- -
- -
-
-
- zip() -
-
-
- -
- -
- -
-
-
- select() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- -
-
- Mutex -
-
-
-
- Mutex() -
-
-
-
- Semaphore -
-
-
- -
-
- -
-
- -
-
-
- -
- -
- -
- -
- -
-
- await() -
-
-
-
- future() -
-
-
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
-
- JavaFx -
-
- -
-
-
- -
- - -
- -
-
-
- await() -
-
-
-
- future() -
-
-
- -
- -
- -
-
-
- delay() -
-
-
- -
-
-
- sample() -
-
-
- -
- -
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
- -
-
-
- -
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
-
- publish() -
-
-
-
- -
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
-
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
- - - -
diff --git a/kotlinx-coroutines-rx2/index.html b/kotlinx-coroutines-rx2/index.html index f5058ae8ce..54cec844ab 100644 --- a/kotlinx-coroutines-rx2/index.html +++ b/kotlinx-coroutines-rx2/index.html @@ -1,72 +1 @@ - - - - - kotlinx-coroutines-rx2 - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

kotlinx-coroutines-rx2

-

Utilities for RxJava 2.x.

Coroutine builders:

NameResultScopeDescription
rxCompletableCompletableCoroutineScopeCold completable that starts coroutine on subscribe
rxMaybeMaybeCoroutineScopeCold maybe that starts coroutine on subscribe
rxSingleSingleCoroutineScopeCold single that starts coroutine on subscribe
rxObservableObservableProducerScopeCold observable that starts coroutine on subscribe
rxFlowableFlowableProducerScopeCold observable that starts coroutine on subscribe with backpressure support

Integration with Flow:

NameResultDescription
Flow.asFlowableFlowableConverts the given flow to a cold Flowable.
Flow.asObservableObservableConverts the given flow to a cold Observable.
ObservableSource.asFlowFlowConverts the given cold ObservableSource to flow

Suspending extension functions and suspending iteration:

NameDescription
CompletableSource.awaitAwaits for completion of the completable value
MaybeSource.awaitSingleAwaits for the value of the maybe and returns it or throws an exception
MaybeSource.awaitSingleOrNullAwaits for the value of the maybe and returns it or null
SingleSource.awaitAwaits for completion of the single value and returns it
ObservableSource.awaitFirstAwaits for the first value from the given observable
ObservableSource.awaitFirstOrDefaultAwaits for the first value from the given observable or default
ObservableSource.awaitFirstOrElseAwaits for the first value from the given observable or default from a function
ObservableSource.awaitFirstOrNullAwaits for the first value from the given observable or null
ObservableSource.awaitLastAwaits for the last value from the given observable
ObservableSource.awaitSingleAwaits for the single value from the given observable

Note that Flowable is a subclass of Reactive StreamsPublisher and extensions for it are covered by ../kotlinx-coroutines-reactive module.

Conversion functions:

NameDescription
Job.asCompletableConverts job to hot completable
Deferred.asSingleConverts deferred value to hot single
Scheduler.asCoroutineDispatcherConverts scheduler to CoroutineDispatcher
-
-

Packages

-
-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-

Utilities for RxJava 2.x.

-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/-scheduler-coroutine-dispatcher/-scheduler-coroutine-dispatcher.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/-scheduler-coroutine-dispatcher/-scheduler-coroutine-dispatcher.html index d45a491696..3b584551c2 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/-scheduler-coroutine-dispatcher/-scheduler-coroutine-dispatcher.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/-scheduler-coroutine-dispatcher/-scheduler-coroutine-dispatcher.html @@ -1,54 +1 @@ - - - - - SchedulerCoroutineDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

SchedulerCoroutineDispatcher

-
-
fun SchedulerCoroutineDispatcher(scheduler: Scheduler)
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/-scheduler-coroutine-dispatcher/index.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/-scheduler-coroutine-dispatcher/index.html index 1a43ab6f94..284e053906 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/-scheduler-coroutine-dispatcher/index.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/-scheduler-coroutine-dispatcher/index.html @@ -1,93 +1 @@ - - - - - SchedulerCoroutineDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

SchedulerCoroutineDispatcher

-
class SchedulerCoroutineDispatcher(val scheduler: Scheduler) : CoroutineDispatcher, Delay

Implements CoroutineDispatcher on top of an arbitrary Scheduler.

-
-
-
-
-

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
fun SchedulerCoroutineDispatcher(scheduler: Scheduler)
-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
val scheduler: Scheduler

Underlying scheduler of current CoroutineDispatcher.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/-scheduler-coroutine-dispatcher/scheduler.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/-scheduler-coroutine-dispatcher/scheduler.html index 163b376931..cd1e191eb1 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/-scheduler-coroutine-dispatcher/scheduler.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/-scheduler-coroutine-dispatcher/scheduler.html @@ -1,54 +1 @@ - - - - - scheduler - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

scheduler

-
-
val scheduler: Scheduler

Underlying scheduler of current CoroutineDispatcher.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-completable.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-completable.html index eddb8ffd13..68450d2694 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-completable.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-completable.html @@ -1,54 +1 @@ - - - - - asCompletable - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asCompletable

-
-
fun Job.asCompletable(context: CoroutineContext): Completable

Converts this job to the hot reactive completable that signals with onCompleted when the corresponding job completes.

Every subscriber gets the signal at the same time. Unsubscribing from the resulting completable does not affect the original job in any way.

Note: This is an experimental api. Conversion of coroutines primitives to reactive entities may change in the future to account for the concept of structured concurrency.

Parameters

context

-- the coroutine context from which the resulting completable is going to be signalled

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-coroutine-dispatcher.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-coroutine-dispatcher.html index 07272ac237..db5063f265 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-coroutine-dispatcher.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-coroutine-dispatcher.html @@ -1,54 +1 @@ - - - - - asCoroutineDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asCoroutineDispatcher

-
-
fun Scheduler.asCoroutineDispatcher(): CoroutineDispatcher

Converts an instance of Scheduler to an implementation of CoroutineDispatcher and provides native support of delay and withTimeout.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-coroutine-dispatcher0.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-coroutine-dispatcher0.html index 05c70e844f..e3f49e6984 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-coroutine-dispatcher0.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-coroutine-dispatcher0.html @@ -1,54 +1 @@ - - - - - asCoroutineDispatcher0 - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asCoroutineDispatcher0

-
-
@JvmName(name = "asCoroutineDispatcher")
fun Scheduler.asCoroutineDispatcher0(): SchedulerCoroutineDispatcher
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-flow.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-flow.html index 3ea133326f..6102883686 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-flow.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-flow.html @@ -1,54 +1 @@ - - - - - asFlow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asFlow

-
-
fun <T : Any> ObservableSource<T>.asFlow(): Flow<T>

Transforms given cold ObservableSource into cold Flow.

The resulting flow is cold, which means that ObservableSource.subscribe is called every time a terminal operator is applied to the resulting flow.

A channel with the default buffer size is used. Use the buffer operator on the resulting flow to specify a user-defined value and to control what happens when data is produced faster than consumed, i.e. to control the back-pressure behavior. Check callbackFlow for more details.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-flowable.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-flowable.html index aa2c529522..b1d3972ff6 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-flowable.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-flowable.html @@ -1,54 +1 @@ - - - - - asFlowable - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asFlowable

-
-
fun <T : Any> Flow<T>.asFlowable(context: CoroutineContext = EmptyCoroutineContext): Flowable<T>

Converts the given flow to a cold flowable. The original flow is cancelled when the flowable subscriber is disposed.

An optional context can be specified to control the execution context of calls to Subscriber methods. You can set a CoroutineDispatcher to confine them to a specific thread and/or various ThreadContextElement to inject additional context into the caller thread. By default, the Unconfined dispatcher is used, so calls are performed from an arbitrary thread.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-maybe.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-maybe.html index ff88665b38..2fe401ec3d 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-maybe.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-maybe.html @@ -1,54 +1 @@ - - - - - asMaybe - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asMaybe

-
-
fun <T> Deferred<T?>.asMaybe(context: CoroutineContext): Maybe<T>

Converts this deferred value to the hot reactive maybe that signals onComplete, onSuccess or onError.

Every subscriber gets the same completion value. Unsubscribing from the resulting maybe does not affect the original deferred value in any way.

Note: This is an experimental api. Conversion of coroutines primitives to reactive entities may change in the future to account for the concept of structured concurrency.

Parameters

context

-- the coroutine context from which the resulting maybe is going to be signalled

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-observable.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-observable.html index 6a1c629bf3..8c368a16f8 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-observable.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-observable.html @@ -1,54 +1 @@ - - - - - asObservable - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asObservable

-
-
fun <T : Any> Flow<T>.asObservable(context: CoroutineContext = EmptyCoroutineContext): Observable<T>

Converts the given flow to a cold observable. The original flow is cancelled when the observable subscriber is disposed.

An optional context can be specified to control the execution context of calls to Observer methods. You can set a CoroutineDispatcher to confine them to a specific thread and/or various ThreadContextElement to inject additional context into the caller thread. By default, the Unconfined dispatcher is used, so calls are performed from an arbitrary thread.


fun <T : Any> ReceiveChannel<T>.asObservable(context: CoroutineContext): Observable<T>
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-scheduler.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-scheduler.html index 297b53eec5..d19536884a 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-scheduler.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-scheduler.html @@ -1,54 +1 @@ - - - - - asScheduler - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asScheduler

-
-
fun CoroutineDispatcher.asScheduler(): Scheduler

Converts an instance of CoroutineDispatcher to an implementation of Scheduler.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-single.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-single.html index e147f2befb..4760a01917 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-single.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/as-single.html @@ -1,54 +1 @@ - - - - - asSingle - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asSingle

-
-
fun <T : Any> Deferred<T>.asSingle(context: CoroutineContext): Single<T>

Converts this deferred value to the hot reactive single that signals either onSuccess or onError.

Every subscriber gets the same completion value. Unsubscribing from the resulting single does not affect the original deferred value in any way.

Note: This is an experimental api. Conversion of coroutines primitives to reactive entities may change in the future to account for the concept of structured concurrency.

Parameters

context

-- the coroutine context from which the resulting single is going to be signalled

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-first-or-default.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-first-or-default.html index 2b0d2b61fa..40e27a52eb 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-first-or-default.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-first-or-default.html @@ -1,54 +1 @@ - - - - - awaitFirstOrDefault - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitFirstOrDefault

-
-
suspend fun <T> ObservableSource<T>.awaitFirstOrDefault(default: T): T

Awaits the first value from the given Observable, or returns the default value if none is emitted, without blocking the thread, and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately disposes of its subscription and resumes with CancellationException.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-first-or-else.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-first-or-else.html index 3969ef8ed1..84f409e492 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-first-or-else.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-first-or-else.html @@ -1,54 +1 @@ - - - - - awaitFirstOrElse - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitFirstOrElse

-
-
suspend fun <T> ObservableSource<T>.awaitFirstOrElse(defaultValue: () -> T): T

Awaits the first value from the given Observable, or calls defaultValue to get a value if none is emitted, without blocking the thread, and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately disposes of its subscription and resumes with CancellationException.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-first-or-null.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-first-or-null.html index 4061de6aad..993c464948 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-first-or-null.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-first-or-null.html @@ -1,54 +1 @@ - - - - - awaitFirstOrNull - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitFirstOrNull

-
-
suspend fun <T> ObservableSource<T>.awaitFirstOrNull(): T?

Awaits the first value from the given Observable, or returns null if none is emitted, without blocking the thread, and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately disposes of its subscription and resumes with CancellationException.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-first.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-first.html index 129fa8bb63..6f0196dc57 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-first.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-first.html @@ -1,54 +1 @@ - - - - - awaitFirst - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitFirst

-
-
suspend fun <T> ObservableSource<T>.awaitFirst(): T

Awaits the first value from the given Observable without blocking the thread and returns the resulting value, or, if the observable has produced an error, throws the corresponding exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately disposes of its subscription and resumes with CancellationException.

Throws

if the observable does not emit any value

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-last.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-last.html index 6e1ed564cc..b73fcf9d3e 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-last.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-last.html @@ -1,54 +1 @@ - - - - - awaitLast - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitLast

-
-
suspend fun <T> ObservableSource<T>.awaitLast(): T

Awaits the last value from the given Observable without blocking the thread and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately disposes of its subscription and resumes with CancellationException.

Throws

if the observable does not emit any value

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-single-or-null.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-single-or-null.html index da354e4bf4..6c2acdec4b 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-single-or-null.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-single-or-null.html @@ -1,54 +1 @@ - - - - - awaitSingleOrNull - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitSingleOrNull

-
-
suspend fun <T> MaybeSource<T>.awaitSingleOrNull(): T?

Awaits for completion of the MaybeSource without blocking the thread. Returns the resulting value, or null if no value is produced, or throws the corresponding exception if this MaybeSource produces an error.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this suspending function is waiting, this function immediately resumes with CancellationException and disposes of its subscription.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-single.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-single.html index 992310827c..9edaa24681 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-single.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await-single.html @@ -1,54 +1 @@ - - - - - awaitSingle - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitSingle

-
-
suspend fun <T> MaybeSource<T>.awaitSingle(): T

Awaits for completion of the MaybeSource without blocking the thread. Returns the resulting value, or throws if either no value is produced or this MaybeSource produces an error.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this suspending function is waiting, this function immediately resumes with CancellationException and disposes of its subscription.

Throws

if no elements were produced by this MaybeSource.


suspend fun <T> ObservableSource<T>.awaitSingle(): T

Awaits the single value from the given observable without blocking the thread and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately disposes of its subscription and resumes with CancellationException.

Throws

if the observable does not emit any value

if the observable emits more than one value

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await.html index dbb212daec..3c2788ff8a 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/await.html @@ -1,54 +1 @@ - - - - - await - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

await

-
-
suspend fun CompletableSource.await()

Awaits for completion of this completable without blocking the thread. Returns Unit, or throws the corresponding exception if this completable produces an error.

This suspending function is cancellable. If the Job of the invoking coroutine is cancelled or completed while this suspending function is suspended, this function immediately resumes with CancellationException and disposes of its subscription.


suspend fun <T> SingleSource<T>.await(): T

Awaits for completion of the single value response without blocking the thread. Returns the resulting value, or throws the corresponding exception if this response produces an error.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately disposes of its subscription and resumes with CancellationException.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/collect.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/collect.html index a734ce5bee..b5d9ecfcc4 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/collect.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/collect.html @@ -1,54 +1 @@ - - - - - collect - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

collect

-
-
inline suspend fun <T> MaybeSource<T>.collect(action: (T) -> Unit)

Subscribes to this MaybeSource and performs the specified action for each received element.

If action throws an exception at some point or if the MaybeSource raises an error, the exception is rethrown from collect.


inline suspend fun <T> ObservableSource<T>.collect(action: (T) -> Unit)

Subscribes to this ObservableSource and performs the specified action for each received element.

If action throws an exception at some point, the subscription is cancelled, and the exception is rethrown from collect. Also, if the ObservableSource signals an error, that error is rethrown from collect.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/index.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/index.html index c94114ad5d..ed5f5d5c90 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/index.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/index.html @@ -1,423 +1 @@ - - - - - kotlinx.coroutines.rx2 - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Package kotlinx.coroutines.rx2

-

Utilities for RxJava 2.x.

-
-
-
-
-

Types

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
class SchedulerCoroutineDispatcher(val scheduler: Scheduler) : CoroutineDispatcher, Delay

Implements CoroutineDispatcher on top of an arbitrary Scheduler.

-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
fun Job.asCompletable(context: CoroutineContext): Completable

Converts this job to the hot reactive completable that signals with onCompleted when the corresponding job completes.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun Scheduler.asCoroutineDispatcher(): CoroutineDispatcher

Converts an instance of Scheduler to an implementation of CoroutineDispatcher and provides native support of delay and withTimeout.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
@JvmName(name = "asCoroutineDispatcher")
fun Scheduler.asCoroutineDispatcher0(): SchedulerCoroutineDispatcher
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T : Any> ObservableSource<T>.asFlow(): Flow<T>

Transforms given cold ObservableSource into cold Flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T : Any> Flow<T>.asFlowable(context: CoroutineContext = EmptyCoroutineContext): Flowable<T>

Converts the given flow to a cold flowable. The original flow is cancelled when the flowable subscriber is disposed.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T> Deferred<T?>.asMaybe(context: CoroutineContext): Maybe<T>

Converts this deferred value to the hot reactive maybe that signals onComplete, onSuccess or onError.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T : Any> ReceiveChannel<T>.asObservable(context: CoroutineContext): Observable<T>

fun <T : Any> Flow<T>.asObservable(context: CoroutineContext = EmptyCoroutineContext): Observable<T>

Converts the given flow to a cold observable. The original flow is cancelled when the observable subscriber is disposed.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun CoroutineDispatcher.asScheduler(): Scheduler

Converts an instance of CoroutineDispatcher to an implementation of Scheduler.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T : Any> Deferred<T>.asSingle(context: CoroutineContext): Single<T>

Converts this deferred value to the hot reactive single that signals either onSuccess or onError.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun CompletableSource.await()

Awaits for completion of this completable without blocking the thread. Returns Unit, or throws the corresponding exception if this completable produces an error.

suspend fun <T> SingleSource<T>.await(): T

Awaits for completion of the single value response without blocking the thread. Returns the resulting value, or throws the corresponding exception if this response produces an error.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> ObservableSource<T>.awaitFirst(): T

Awaits the first value from the given Observable without blocking the thread and returns the resulting value, or, if the observable has produced an error, throws the corresponding exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> ObservableSource<T>.awaitFirstOrDefault(default: T): T

Awaits the first value from the given Observable, or returns the default value if none is emitted, without blocking the thread, and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> ObservableSource<T>.awaitFirstOrElse(defaultValue: () -> T): T

Awaits the first value from the given Observable, or calls defaultValue to get a value if none is emitted, without blocking the thread, and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> ObservableSource<T>.awaitFirstOrNull(): T?

Awaits the first value from the given Observable, or returns null if none is emitted, without blocking the thread, and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> ObservableSource<T>.awaitLast(): T

Awaits the last value from the given Observable without blocking the thread and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> MaybeSource<T>.awaitSingle(): T

Awaits for completion of the MaybeSource without blocking the thread. Returns the resulting value, or throws if either no value is produced or this MaybeSource produces an error.

suspend fun <T> ObservableSource<T>.awaitSingle(): T

Awaits the single value from the given observable without blocking the thread and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> MaybeSource<T>.awaitSingleOrNull(): T?

Awaits for completion of the MaybeSource without blocking the thread. Returns the resulting value, or null if no value is produced, or throws the corresponding exception if this MaybeSource produces an error.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
inline suspend fun <T> MaybeSource<T>.collect(action: (T) -> Unit)

Subscribes to this MaybeSource and performs the specified action for each received element.

inline suspend fun <T> ObservableSource<T>.collect(action: (T) -> Unit)

Subscribes to this ObservableSource and performs the specified action for each received element.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun rxCompletable(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> Unit): Completable

Creates cold Completable that runs a given block in a coroutine and emits its result. Every time the returned completable is subscribed, it starts a new coroutine. Unsubscribing cancels running coroutine. Coroutine context can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. Method throws IllegalArgumentException if provided context contains a Job instance.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T : Any> rxFlowable(context: CoroutineContext = EmptyCoroutineContext, block: suspend ProducerScope<T>.() -> Unit): Flowable<T>

Creates cold flowable that will run a given block in a coroutine. Every time the returned flowable is subscribed, it starts a new coroutine.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T> rxMaybe(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T?): Maybe<T>

Creates cold maybe that will run a given block in a coroutine and emits its result. If block result is null, onComplete is invoked without a value. Every time the returned observable is subscribed, it starts a new coroutine. Unsubscribing cancels running coroutine. Coroutine context can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. Method throws IllegalArgumentException if provided context contains a Job instance.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T : Any> rxObservable(context: CoroutineContext = EmptyCoroutineContext, block: suspend ProducerScope<T>.() -> Unit): Observable<T>

Creates cold observable that will run a given block in a coroutine. Every time the returned observable is subscribed, it starts a new coroutine.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T : Any> rxSingle(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): Single<T>

Creates cold single that will run a given block in a coroutine and emits its result. Every time the returned observable is subscribed, it starts a new coroutine. Unsubscribing cancels running coroutine. Coroutine context can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. Method throws IllegalArgumentException if provided context contains a Job instance.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-completable.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-completable.html index 4949746121..548e6ec27b 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-completable.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-completable.html @@ -1,54 +1 @@ - - - - - rxCompletable - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

rxCompletable

-
-
fun rxCompletable(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> Unit): Completable

Creates cold Completable that runs a given block in a coroutine and emits its result. Every time the returned completable is subscribed, it starts a new coroutine. Unsubscribing cancels running coroutine. Coroutine context can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. Method throws IllegalArgumentException if provided context contains a Job instance.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-flowable.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-flowable.html index 802e7509c0..9524dbe024 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-flowable.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-flowable.html @@ -1,54 +1 @@ - - - - - rxFlowable - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

rxFlowable

-
-
fun <T : Any> rxFlowable(context: CoroutineContext = EmptyCoroutineContext, block: suspend ProducerScope<T>.() -> Unit): Flowable<T>

Creates cold flowable that will run a given block in a coroutine. Every time the returned flowable is subscribed, it starts a new coroutine.

Coroutine emits (ObservableEmitter.onNext) values with send, completes (ObservableEmitter.onComplete) when the coroutine completes or channel is explicitly closed and emits error (ObservableEmitter.onError) if coroutine throws an exception or closes channel with a cause. Unsubscribing cancels running coroutine.

Invocations of send are suspended appropriately when subscribers apply back-pressure and to ensure that onNext is not invoked concurrently.

Coroutine context can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. Method throws IllegalArgumentException if provided context contains a Job instance.

Note: This is an experimental api. Behaviour of publishers that work as children in a parent scope with respect

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-maybe.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-maybe.html index 3ec2a00162..ad3dc0b621 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-maybe.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-maybe.html @@ -1,54 +1 @@ - - - - - rxMaybe - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

rxMaybe

-
-
fun <T> rxMaybe(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T?): Maybe<T>

Creates cold maybe that will run a given block in a coroutine and emits its result. If block result is null, onComplete is invoked without a value. Every time the returned observable is subscribed, it starts a new coroutine. Unsubscribing cancels running coroutine. Coroutine context can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. Method throws IllegalArgumentException if provided context contains a Job instance.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-observable.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-observable.html index b56a741d73..665c07afdd 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-observable.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-observable.html @@ -1,54 +1 @@ - - - - - rxObservable - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

rxObservable

-
-
fun <T : Any> rxObservable(context: CoroutineContext = EmptyCoroutineContext, block: suspend ProducerScope<T>.() -> Unit): Observable<T>

Creates cold observable that will run a given block in a coroutine. Every time the returned observable is subscribed, it starts a new coroutine.

Coroutine emits (ObservableEmitter.onNext) values with send, completes (ObservableEmitter.onComplete) when the coroutine completes or channel is explicitly closed and emits error (ObservableEmitter.onError) if coroutine throws an exception or closes channel with a cause. Unsubscribing cancels running coroutine.

Invocations of send are suspended appropriately to ensure that onNext is not invoked concurrently. Note that Rx 2.x Observabledoes not support backpressure.

Coroutine context can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. Method throws IllegalArgumentException if provided context contains a Job instance.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-single.html b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-single.html index f718cf761a..0b0770cd6e 100644 --- a/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-single.html +++ b/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-single.html @@ -1,54 +1 @@ - - - - - rxSingle - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

rxSingle

-
-
fun <T : Any> rxSingle(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): Single<T>

Creates cold single that will run a given block in a coroutine and emits its result. Every time the returned observable is subscribed, it starts a new coroutine. Unsubscribing cancels running coroutine. Coroutine context can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. Method throws IllegalArgumentException if provided context contains a Job instance.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx2/navigation.html b/kotlinx-coroutines-rx2/navigation.html deleted file mode 100644 index be03fe14df..0000000000 --- a/kotlinx-coroutines-rx2/navigation.html +++ /dev/null @@ -1,2047 +0,0 @@ -
- -
- -
- - - -
- -
-
- -
-
- -
-
-
- async() -
-
-
-
- await() -
-
-
- -
- - -
-
- cancel() -
-
-
- -
- - - - - - - - -
- -
-
- -
- - - - - -
- -
-
- -
- - -
- -
-
- ATOMIC -
-
-
-
- DEFAULT -
-
-
-
- LAZY -
-
-
- -
-
- - - - - -
-
- Deferred -
-
-
-
- delay() -
-
- -
- -
- -
- -
-
- -
- - -
- -
-
- -
- - -
-
- invoke() -
-
- -
-
- isActive -
-
-
- -
-
-
- Job -
-
-
-
- job -
-
-
-
- Job() -
-
-
-
- joinAll() -
-
-
-
- launch() -
-
- -
- -
- - - -
- -
- -
-
- plus() -
-
-
-
- promise() -
-
-
- -
- -
-
- Runnable -
-
-
- -
-
- -
- - - - -
- -
-
- -
- -
-
- yield() -
-
-
-
- -
-
- actor() -
-
-
- -
-
- -
-
- -
- - -
- -
- -
-
- -
-
-
- SUSPEND -
-
-
-
-
- Channel -
-
-
-
- Channel() -
-
-
- -
-
- -
- - - -
-
- consume() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- produce() -
-
-
- -
-
- -
-
- -
-
-
- ticker() -
-
-
- -
- -
-
- -
-
-
-
- toList() -
-
- -
-
- -
- -
-
-
- asFlow() -
-
-
- -
-
- -
-
-
- buffer() -
-
-
- -
-
- -
-
-
- catch() -
-
-
- -
-
-
- collect() -
-
- -
- -
-
-
- combine() -
-
- -
- -
-
- -
-
-
- count() -
-
-
- -
- - - - -
-
- drop() -
-
-
- -
-
-
- emitAll() -
-
-
- -
-
-
- filter() -
-
- -
- -
-
- -
-
-
- first() -
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
- Flow -
-
-
-
- flow() -
-
-
- -
-
-
- flowOf() -
-
-
-
- flowOn() -
-
-
-
- fold() -
-
-
- -
-
-
- last() -
-
-
- -
-
- -
-
-
- map() -
-
-
- -
-
- -
-
-
- merge() -
-
- - - - -
- -
-
-
- onEach() -
-
-
-
- onEmpty() -
-
-
-
- onStart() -
-
- -
- -
-
- -
-
-
- reduce() -
-
-
-
- retry() -
-
-
- -
-
- -
-
- -
-
-
- sample() -
-
-
-
- scan() -
-
-
- -
-
-
- shareIn() -
-
-
- -
-
- START -
-
-
-
- STOP -
-
- -
-
- -
-
-
- single() -
-
-
- -
-
-
- StateFlow -
-
-
-
- stateIn() -
-
-
-
- take() -
-
-
- -
-
- -
-
-
- toList() -
-
-
-
- toSet() -
-
-
- -
- - -
-
- update() -
-
-
- -
- -
- -
-
-
- zip() -
-
-
- -
- -
- -
-
-
- select() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- -
-
- Mutex -
-
-
-
- Mutex() -
-
-
-
- Semaphore -
-
-
- -
-
- -
-
- -
-
-
- -
- -
- -
- -
- -
-
- await() -
-
-
-
- future() -
-
-
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
-
- JavaFx -
-
- -
-
-
- -
- - -
- -
-
-
- await() -
-
-
-
- future() -
-
-
- -
- -
- -
-
-
- delay() -
-
-
- -
-
-
- sample() -
-
-
- -
- -
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
- -
-
-
- -
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
-
- publish() -
-
-
-
- -
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
-
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
- - - -
diff --git a/kotlinx-coroutines-rx3/index.html b/kotlinx-coroutines-rx3/index.html index e453685dc8..6265c0d0bd 100644 --- a/kotlinx-coroutines-rx3/index.html +++ b/kotlinx-coroutines-rx3/index.html @@ -1,72 +1 @@ - - - - - kotlinx-coroutines-rx3 - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

kotlinx-coroutines-rx3

-

Utilities for RxJava 3.x.

Coroutine builders:

NameResultScopeDescription
rxCompletableCompletableCoroutineScopeCold completable that starts coroutine on subscribe
rxMaybeMaybeCoroutineScopeCold maybe that starts coroutine on subscribe
rxSingleSingleCoroutineScopeCold single that starts coroutine on subscribe
rxObservableObservableProducerScopeCold observable that starts coroutine on subscribe
rxFlowableFlowableProducerScopeCold observable that starts coroutine on subscribe with backpressure support

Integration with Flow:

NameResultDescription
Flow.asFlowableFlowableConverts the given flow to a cold Flowable.
Flow.asObservableObservableConverts the given flow to a cold Observable.
ObservableSource.asFlowFlowConverts the given cold ObservableSource to flow

Suspending extension functions and suspending iteration:

NameDescription
CompletableSource.awaitAwaits for completion of the completable value
MaybeSource.awaitSingleAwaits for the value of the maybe and returns it or throws an exception
MaybeSource.awaitSingleOrNullAwaits for the value of the maybe and returns it or null
SingleSource.awaitAwaits for completion of the single value and returns it
ObservableSource.awaitFirstAwaits for the first value from the given observable
ObservableSource.awaitFirstOrDefaultAwaits for the first value from the given observable or default
ObservableSource.awaitFirstOrElseAwaits for the first value from the given observable or default from a function
ObservableSource.awaitFirstOrNullAwaits for the first value from the given observable or null
ObservableSource.awaitLastAwaits for the last value from the given observable
ObservableSource.awaitSingleAwaits for the single value from the given observable

Note that Flowable is a subclass of Reactive StreamsPublisher and extensions for it are covered by ../kotlinx-coroutines-reactive module.

Conversion functions:

NameDescription
Job.asCompletableConverts job to hot completable
Deferred.asSingleConverts deferred value to hot single
Scheduler.asCoroutineDispatcherConverts scheduler to CoroutineDispatcher
-
-

Packages

-
-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-

Utilities for RxJava 3.x.

-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/-scheduler-coroutine-dispatcher/-scheduler-coroutine-dispatcher.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/-scheduler-coroutine-dispatcher/-scheduler-coroutine-dispatcher.html index 053d0f0d18..0cc5ff9330 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/-scheduler-coroutine-dispatcher/-scheduler-coroutine-dispatcher.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/-scheduler-coroutine-dispatcher/-scheduler-coroutine-dispatcher.html @@ -1,54 +1 @@ - - - - - SchedulerCoroutineDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

SchedulerCoroutineDispatcher

-
-
fun SchedulerCoroutineDispatcher(scheduler: Scheduler)
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/-scheduler-coroutine-dispatcher/index.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/-scheduler-coroutine-dispatcher/index.html index 443ac3c7bf..7576c66571 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/-scheduler-coroutine-dispatcher/index.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/-scheduler-coroutine-dispatcher/index.html @@ -1,93 +1 @@ - - - - - SchedulerCoroutineDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

SchedulerCoroutineDispatcher

-
class SchedulerCoroutineDispatcher(val scheduler: Scheduler) : CoroutineDispatcher, Delay

Implements CoroutineDispatcher on top of an arbitrary Scheduler.

-
-
-
-
-

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
fun SchedulerCoroutineDispatcher(scheduler: Scheduler)
-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
val scheduler: Scheduler

Underlying scheduler of current CoroutineDispatcher.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/-scheduler-coroutine-dispatcher/scheduler.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/-scheduler-coroutine-dispatcher/scheduler.html index 59d1c31831..d197d9ad20 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/-scheduler-coroutine-dispatcher/scheduler.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/-scheduler-coroutine-dispatcher/scheduler.html @@ -1,54 +1 @@ - - - - - scheduler - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

scheduler

-
-
val scheduler: Scheduler

Underlying scheduler of current CoroutineDispatcher.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-completable.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-completable.html index b67ebc81cd..6cb0921945 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-completable.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-completable.html @@ -1,54 +1 @@ - - - - - asCompletable - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asCompletable

-
-
fun Job.asCompletable(context: CoroutineContext): Completable

Converts this job to the hot reactive completable that signals with onCompleted when the corresponding job completes.

Every subscriber gets the signal at the same time. Unsubscribing from the resulting completable does not affect the original job in any way.

Note: This is an experimental api. Conversion of coroutines primitives to reactive entities may change in the future to account for the concept of structured concurrency.

Parameters

context

-- the coroutine context from which the resulting completable is going to be signalled

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-coroutine-dispatcher.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-coroutine-dispatcher.html index ffb599a3dc..ea6137ddf0 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-coroutine-dispatcher.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-coroutine-dispatcher.html @@ -1,54 +1 @@ - - - - - asCoroutineDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asCoroutineDispatcher

-
-
fun Scheduler.asCoroutineDispatcher(): CoroutineDispatcher

Converts an instance of Scheduler to an implementation of CoroutineDispatcher and provides native support of delay and withTimeout.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-coroutine-dispatcher0.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-coroutine-dispatcher0.html index 8216567a3f..ed09597493 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-coroutine-dispatcher0.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-coroutine-dispatcher0.html @@ -1,54 +1 @@ - - - - - asCoroutineDispatcher0 - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asCoroutineDispatcher0

-
-
@JvmName(name = "asCoroutineDispatcher")
fun Scheduler.asCoroutineDispatcher0(): SchedulerCoroutineDispatcher
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-flow.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-flow.html index b885c30321..45b4e79a2d 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-flow.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-flow.html @@ -1,54 +1 @@ - - - - - asFlow - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asFlow

-
-
fun <T : Any> ObservableSource<T>.asFlow(): Flow<T>

Transforms given cold ObservableSource into cold Flow.

The resulting flow is cold, which means that ObservableSource.subscribe is called every time a terminal operator is applied to the resulting flow.

A channel with the default buffer size is used. Use the buffer operator on the resulting flow to specify a user-defined value and to control what happens when data is produced faster than consumed, i.e. to control the back-pressure behavior. Check callbackFlow for more details.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-flowable.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-flowable.html index 0de1a2b764..3e37d2d557 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-flowable.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-flowable.html @@ -1,54 +1 @@ - - - - - asFlowable - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asFlowable

-
-
fun <T : Any> Flow<T>.asFlowable(context: CoroutineContext = EmptyCoroutineContext): Flowable<T>

Converts the given flow to a cold flowable. The original flow is cancelled when the flowable subscriber is disposed.

An optional context can be specified to control the execution context of calls to Subscriber methods. You can set a CoroutineDispatcher to confine them to a specific thread and/or various ThreadContextElement to inject additional context into the caller thread. By default, the Unconfined dispatcher is used, so calls are performed from an arbitrary thread.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-maybe.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-maybe.html index 589db9f2a2..71dc68e6ce 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-maybe.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-maybe.html @@ -1,54 +1 @@ - - - - - asMaybe - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asMaybe

-
-
fun <T> Deferred<T?>.asMaybe(context: CoroutineContext): Maybe<T>

Converts this deferred value to the hot reactive maybe that signals onComplete, onSuccess or onError.

Every subscriber gets the same completion value. Unsubscribing from the resulting maybe does not affect the original deferred value in any way.

Note: This is an experimental api. Conversion of coroutines primitives to reactive entities may change in the future to account for the concept of structured concurrency.

Parameters

context

-- the coroutine context from which the resulting maybe is going to be signalled

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-observable.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-observable.html index 37aa2a710b..2724f6451f 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-observable.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-observable.html @@ -1,54 +1 @@ - - - - - asObservable - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asObservable

-
-
fun <T : Any> Flow<T>.asObservable(context: CoroutineContext = EmptyCoroutineContext): Observable<T>

Converts the given flow to a cold observable. The original flow is cancelled when the observable subscriber is disposed.

An optional context can be specified to control the execution context of calls to Observer methods. You can set a CoroutineDispatcher to confine them to a specific thread and/or various ThreadContextElement to inject additional context into the caller thread. By default, the Unconfined dispatcher is used, so calls are performed from an arbitrary thread.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-scheduler.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-scheduler.html index 478339c06f..49e8de4ef4 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-scheduler.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-scheduler.html @@ -1,54 +1 @@ - - - - - asScheduler - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asScheduler

-
-
fun CoroutineDispatcher.asScheduler(): Scheduler

Converts an instance of CoroutineDispatcher to an implementation of Scheduler.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-single.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-single.html index 6bacf7fc0e..ea8cbdba09 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-single.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/as-single.html @@ -1,54 +1 @@ - - - - - asSingle - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

asSingle

-
-
fun <T : Any> Deferred<T>.asSingle(context: CoroutineContext): Single<T>

Converts this deferred value to the hot reactive single that signals either onSuccess or onError.

Every subscriber gets the same completion value. Unsubscribing from the resulting single does not affect the original deferred value in any way.

Note: This is an experimental api. Conversion of coroutines primitives to reactive entities may change in the future to account for the concept of structured concurrency.

Parameters

context

-- the coroutine context from which the resulting single is going to be signalled

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-first-or-default.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-first-or-default.html index 501fe89d67..f1bf3dfb93 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-first-or-default.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-first-or-default.html @@ -1,54 +1 @@ - - - - - awaitFirstOrDefault - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitFirstOrDefault

-
-
suspend fun <T> ObservableSource<T>.awaitFirstOrDefault(default: T): T

Awaits the first value from the given Observable, or returns the default value if none is emitted, without blocking the thread, and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately disposes of its subscription and resumes with CancellationException.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-first-or-else.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-first-or-else.html index 412cb381b0..f682b56e89 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-first-or-else.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-first-or-else.html @@ -1,54 +1 @@ - - - - - awaitFirstOrElse - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitFirstOrElse

-
-
suspend fun <T> ObservableSource<T>.awaitFirstOrElse(defaultValue: () -> T): T

Awaits the first value from the given Observable, or calls defaultValue to get a value if none is emitted, without blocking the thread, and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately disposes of its subscription and resumes with CancellationException.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-first-or-null.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-first-or-null.html index 7ed5961c16..36a18377c0 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-first-or-null.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-first-or-null.html @@ -1,54 +1 @@ - - - - - awaitFirstOrNull - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitFirstOrNull

-
-
suspend fun <T> ObservableSource<T>.awaitFirstOrNull(): T?

Awaits the first value from the given Observable, or returns null if none is emitted, without blocking the thread, and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately disposes of its subscription and resumes with CancellationException.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-first.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-first.html index 17390d0f64..47f076d54a 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-first.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-first.html @@ -1,54 +1 @@ - - - - - awaitFirst - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitFirst

-
-
suspend fun <T> ObservableSource<T>.awaitFirst(): T

Awaits the first value from the given Observable without blocking the thread and returns the resulting value, or, if the observable has produced an error, throws the corresponding exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately disposes of its subscription and resumes with CancellationException.

Throws

if the observable does not emit any value

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-last.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-last.html index 86c9fec000..cf32ed2343 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-last.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-last.html @@ -1,54 +1 @@ - - - - - awaitLast - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitLast

-
-
suspend fun <T> ObservableSource<T>.awaitLast(): T

Awaits the last value from the given Observable without blocking the thread and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately disposes of its subscription and resumes with CancellationException.

Throws

if the observable does not emit any value

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-single-or-null.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-single-or-null.html index 3690497bad..b18dc4360d 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-single-or-null.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-single-or-null.html @@ -1,54 +1 @@ - - - - - awaitSingleOrNull - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitSingleOrNull

-
-
suspend fun <T> MaybeSource<T>.awaitSingleOrNull(): T?

Awaits for completion of the MaybeSource without blocking the thread. Returns the resulting value, or null if no value is produced, or throws the corresponding exception if this MaybeSource produces an error.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this suspending function is waiting, this function immediately resumes with CancellationException and disposes of its subscription.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-single.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-single.html index cd858c4650..629557288d 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-single.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await-single.html @@ -1,54 +1 @@ - - - - - awaitSingle - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

awaitSingle

-
-
suspend fun <T> MaybeSource<T>.awaitSingle(): T

Awaits for completion of the MaybeSource without blocking the thread. Returns the resulting value, or throws if either no value is produced or this MaybeSource produces an error.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this suspending function is waiting, this function immediately resumes with CancellationException and disposes of its subscription.

Throws

if no elements were produced by this MaybeSource.


suspend fun <T> ObservableSource<T>.awaitSingle(): T

Awaits the single value from the given observable without blocking the thread and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately disposes of its subscription and resumes with CancellationException.

Throws

if the observable does not emit any value

if the observable emits more than one value

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await.html index f07f193a3d..8ae70478d6 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/await.html @@ -1,54 +1 @@ - - - - - await - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

await

-
-
suspend fun CompletableSource.await()

Awaits for completion of this completable without blocking the thread. Returns Unit, or throws the corresponding exception if this completable produces an error.

This suspending function is cancellable. If the Job of the invoking coroutine is cancelled or completed while this suspending function is suspended, this function immediately resumes with CancellationException and disposes of its subscription.


suspend fun <T> SingleSource<T>.await(): T

Awaits for completion of the single value response without blocking the thread. Returns the resulting value, or throws the corresponding exception if this response produces an error.

This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while the suspending function is waiting, this function immediately disposes of its subscription and resumes with CancellationException.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/collect.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/collect.html index 63ee761738..7636ddb050 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/collect.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/collect.html @@ -1,54 +1 @@ - - - - - collect - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

collect

-
-
inline suspend fun <T> MaybeSource<T>.collect(action: (T) -> Unit)

Subscribes to this MaybeSource and performs the specified action for each received element.

If action throws an exception at some point or if the MaybeSource raises an error, the exception is rethrown from collect.


inline suspend fun <T> ObservableSource<T>.collect(action: (T) -> Unit)

Subscribes to this ObservableSource and performs the specified action for each received element.

If action throws an exception at some point, the subscription is cancelled, and the exception is rethrown from collect. Also, if the ObservableSource signals an error, that error is rethrown from collect.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/index.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/index.html index 82ab7b38f0..bad1eb23f1 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/index.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/index.html @@ -1,423 +1 @@ - - - - - kotlinx.coroutines.rx3 - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Package kotlinx.coroutines.rx3

-

Utilities for RxJava 3.x.

-
-
-
-
-

Types

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
class SchedulerCoroutineDispatcher(val scheduler: Scheduler) : CoroutineDispatcher, Delay

Implements CoroutineDispatcher on top of an arbitrary Scheduler.

-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
fun Job.asCompletable(context: CoroutineContext): Completable

Converts this job to the hot reactive completable that signals with onCompleted when the corresponding job completes.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun Scheduler.asCoroutineDispatcher(): CoroutineDispatcher

Converts an instance of Scheduler to an implementation of CoroutineDispatcher and provides native support of delay and withTimeout.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
@JvmName(name = "asCoroutineDispatcher")
fun Scheduler.asCoroutineDispatcher0(): SchedulerCoroutineDispatcher
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T : Any> ObservableSource<T>.asFlow(): Flow<T>

Transforms given cold ObservableSource into cold Flow.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T : Any> Flow<T>.asFlowable(context: CoroutineContext = EmptyCoroutineContext): Flowable<T>

Converts the given flow to a cold flowable. The original flow is cancelled when the flowable subscriber is disposed.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T> Deferred<T?>.asMaybe(context: CoroutineContext): Maybe<T>

Converts this deferred value to the hot reactive maybe that signals onComplete, onSuccess or onError.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T : Any> Flow<T>.asObservable(context: CoroutineContext = EmptyCoroutineContext): Observable<T>

Converts the given flow to a cold observable. The original flow is cancelled when the observable subscriber is disposed.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun CoroutineDispatcher.asScheduler(): Scheduler

Converts an instance of CoroutineDispatcher to an implementation of Scheduler.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T : Any> Deferred<T>.asSingle(context: CoroutineContext): Single<T>

Converts this deferred value to the hot reactive single that signals either onSuccess or onError.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun CompletableSource.await()

Awaits for completion of this completable without blocking the thread. Returns Unit, or throws the corresponding exception if this completable produces an error.

suspend fun <T> SingleSource<T>.await(): T

Awaits for completion of the single value response without blocking the thread. Returns the resulting value, or throws the corresponding exception if this response produces an error.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> ObservableSource<T>.awaitFirst(): T

Awaits the first value from the given Observable without blocking the thread and returns the resulting value, or, if the observable has produced an error, throws the corresponding exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> ObservableSource<T>.awaitFirstOrDefault(default: T): T

Awaits the first value from the given Observable, or returns the default value if none is emitted, without blocking the thread, and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> ObservableSource<T>.awaitFirstOrElse(defaultValue: () -> T): T

Awaits the first value from the given Observable, or calls defaultValue to get a value if none is emitted, without blocking the thread, and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> ObservableSource<T>.awaitFirstOrNull(): T?

Awaits the first value from the given Observable, or returns null if none is emitted, without blocking the thread, and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> ObservableSource<T>.awaitLast(): T

Awaits the last value from the given Observable without blocking the thread and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> MaybeSource<T>.awaitSingle(): T

Awaits for completion of the MaybeSource without blocking the thread. Returns the resulting value, or throws if either no value is produced or this MaybeSource produces an error.

suspend fun <T> ObservableSource<T>.awaitSingle(): T

Awaits the single value from the given observable without blocking the thread and returns the resulting value, or, if this observable has produced an error, throws the corresponding exception.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
suspend fun <T> MaybeSource<T>.awaitSingleOrNull(): T?

Awaits for completion of the MaybeSource without blocking the thread. Returns the resulting value, or null if no value is produced, or throws the corresponding exception if this MaybeSource produces an error.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
inline suspend fun <T> MaybeSource<T>.collect(action: (T) -> Unit)

Subscribes to this MaybeSource and performs the specified action for each received element.

inline suspend fun <T> ObservableSource<T>.collect(action: (T) -> Unit)

Subscribes to this ObservableSource and performs the specified action for each received element.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun rxCompletable(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> Unit): Completable

Creates cold Completable that runs a given block in a coroutine and emits its result. Every time the returned completable is subscribed, it starts a new coroutine. Unsubscribing cancels running coroutine. Coroutine context can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. Method throws IllegalArgumentException if provided context contains a Job instance.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T : Any> rxFlowable(context: CoroutineContext = EmptyCoroutineContext, block: suspend ProducerScope<T>.() -> Unit): Flowable<T>

Creates cold flowable that will run a given block in a coroutine. Every time the returned flowable is subscribed, it starts a new coroutine.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T> rxMaybe(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T?): Maybe<T>

Creates cold maybe that will run a given block in a coroutine and emits its result. If block result is null, onComplete is invoked without a value. Every time the returned observable is subscribed, it starts a new coroutine. Unsubscribing cancels running coroutine. Coroutine context can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. Method throws IllegalArgumentException if provided context contains a Job instance.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T : Any> rxObservable(context: CoroutineContext = EmptyCoroutineContext, block: suspend ProducerScope<T>.() -> Unit): Observable<T>

Creates cold observable that will run a given block in a coroutine. Every time the returned observable is subscribed, it starts a new coroutine.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
fun <T : Any> rxSingle(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): Single<T>

Creates cold single that will run a given block in a coroutine and emits its result. Every time the returned observable is subscribed, it starts a new coroutine. Unsubscribing cancels running coroutine. Coroutine context can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. Method throws IllegalArgumentException if provided context contains a Job instance.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/rx-completable.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/rx-completable.html index ea6f6bb1c4..578aa01275 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/rx-completable.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/rx-completable.html @@ -1,54 +1 @@ - - - - - rxCompletable - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

rxCompletable

-
-
fun rxCompletable(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> Unit): Completable

Creates cold Completable that runs a given block in a coroutine and emits its result. Every time the returned completable is subscribed, it starts a new coroutine. Unsubscribing cancels running coroutine. Coroutine context can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. Method throws IllegalArgumentException if provided context contains a Job instance.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/rx-flowable.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/rx-flowable.html index 580f1a0c6a..e363431202 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/rx-flowable.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/rx-flowable.html @@ -1,54 +1 @@ - - - - - rxFlowable - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

rxFlowable

-
-
fun <T : Any> rxFlowable(context: CoroutineContext = EmptyCoroutineContext, block: suspend ProducerScope<T>.() -> Unit): Flowable<T>

Creates cold flowable that will run a given block in a coroutine. Every time the returned flowable is subscribed, it starts a new coroutine.

Coroutine emits (ObservableEmitter.onNext) values with send, completes (ObservableEmitter.onComplete) when the coroutine completes or channel is explicitly closed and emits error (ObservableEmitter.onError) if coroutine throws an exception or closes channel with a cause. Unsubscribing cancels running coroutine.

Invocations of send are suspended appropriately when subscribers apply back-pressure and to ensure that onNext is not invoked concurrently.

Coroutine context can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. Method throws IllegalArgumentException if provided context contains a Job instance.

Note: This is an experimental api. Behaviour of publishers that work as children in a parent scope with respect

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/rx-maybe.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/rx-maybe.html index cd2d83f71c..3412f13113 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/rx-maybe.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/rx-maybe.html @@ -1,54 +1 @@ - - - - - rxMaybe - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

rxMaybe

-
-
fun <T> rxMaybe(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T?): Maybe<T>

Creates cold maybe that will run a given block in a coroutine and emits its result. If block result is null, onComplete is invoked without a value. Every time the returned observable is subscribed, it starts a new coroutine. Unsubscribing cancels running coroutine. Coroutine context can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. Method throws IllegalArgumentException if provided context contains a Job instance.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/rx-observable.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/rx-observable.html index 4c1d09b392..eaabc2e3e6 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/rx-observable.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/rx-observable.html @@ -1,54 +1 @@ - - - - - rxObservable - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

rxObservable

-
-
fun <T : Any> rxObservable(context: CoroutineContext = EmptyCoroutineContext, block: suspend ProducerScope<T>.() -> Unit): Observable<T>

Creates cold observable that will run a given block in a coroutine. Every time the returned observable is subscribed, it starts a new coroutine.

Coroutine emits (ObservableEmitter.onNext) values with send, completes (ObservableEmitter.onComplete) when the coroutine completes or channel is explicitly closed and emits error (ObservableEmitter.onError) if coroutine throws an exception or closes channel with a cause. Unsubscribing cancels running coroutine.

Invocations of send are suspended appropriately to ensure that onNext is not invoked concurrently. Note that Rx 2.x Observabledoes not support backpressure.

Coroutine context can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. Method throws IllegalArgumentException if provided context contains a Job instance.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/rx-single.html b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/rx-single.html index 0f04f77075..9e94327798 100644 --- a/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/rx-single.html +++ b/kotlinx-coroutines-rx3/kotlinx.coroutines.rx3/rx-single.html @@ -1,54 +1 @@ - - - - - rxSingle - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

rxSingle

-
-
fun <T : Any> rxSingle(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): Single<T>

Creates cold single that will run a given block in a coroutine and emits its result. Every time the returned observable is subscribed, it starts a new coroutine. Unsubscribing cancels running coroutine. Coroutine context can be specified with context argument. If the context does not have any dispatcher nor any other ContinuationInterceptor, then Dispatchers.Default is used. Method throws IllegalArgumentException if provided context contains a Job instance.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-rx3/navigation.html b/kotlinx-coroutines-rx3/navigation.html deleted file mode 100644 index be03fe14df..0000000000 --- a/kotlinx-coroutines-rx3/navigation.html +++ /dev/null @@ -1,2047 +0,0 @@ -
- -
- -
- - - -
- -
-
- -
-
- -
-
-
- async() -
-
-
-
- await() -
-
-
- -
- - -
-
- cancel() -
-
-
- -
- - - - - - - - -
- -
-
- -
- - - - - -
- -
-
- -
- - -
- -
-
- ATOMIC -
-
-
-
- DEFAULT -
-
-
-
- LAZY -
-
-
- -
-
- - - - - -
-
- Deferred -
-
-
-
- delay() -
-
- -
- -
- -
- -
-
- -
- - -
- -
-
- -
- - -
-
- invoke() -
-
- -
-
- isActive -
-
-
- -
-
-
- Job -
-
-
-
- job -
-
-
-
- Job() -
-
-
-
- joinAll() -
-
-
-
- launch() -
-
- -
- -
- - - -
- -
- -
-
- plus() -
-
-
-
- promise() -
-
-
- -
- -
-
- Runnable -
-
-
- -
-
- -
- - - - -
- -
-
- -
- -
-
- yield() -
-
-
-
- -
-
- actor() -
-
-
- -
-
- -
-
- -
- - -
- -
- -
-
- -
-
-
- SUSPEND -
-
-
-
-
- Channel -
-
-
-
- Channel() -
-
-
- -
-
- -
- - - -
-
- consume() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- produce() -
-
-
- -
-
- -
-
- -
-
-
- ticker() -
-
-
- -
- -
-
- -
-
-
-
- toList() -
-
- -
-
- -
- -
-
-
- asFlow() -
-
-
- -
-
- -
-
-
- buffer() -
-
-
- -
-
- -
-
-
- catch() -
-
-
- -
-
-
- collect() -
-
- -
- -
-
-
- combine() -
-
- -
- -
-
- -
-
-
- count() -
-
-
- -
- - - - -
-
- drop() -
-
-
- -
-
-
- emitAll() -
-
-
- -
-
-
- filter() -
-
- -
- -
-
- -
-
-
- first() -
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
- Flow -
-
-
-
- flow() -
-
-
- -
-
-
- flowOf() -
-
-
-
- flowOn() -
-
-
-
- fold() -
-
-
- -
-
-
- last() -
-
-
- -
-
- -
-
-
- map() -
-
-
- -
-
- -
-
-
- merge() -
-
- - - - -
- -
-
-
- onEach() -
-
-
-
- onEmpty() -
-
-
-
- onStart() -
-
- -
- -
-
- -
-
-
- reduce() -
-
-
-
- retry() -
-
-
- -
-
- -
-
- -
-
-
- sample() -
-
-
-
- scan() -
-
-
- -
-
-
- shareIn() -
-
-
- -
-
- START -
-
-
-
- STOP -
-
- -
-
- -
-
-
- single() -
-
-
- -
-
-
- StateFlow -
-
-
-
- stateIn() -
-
-
-
- take() -
-
-
- -
-
- -
-
-
- toList() -
-
-
-
- toSet() -
-
-
- -
- - -
-
- update() -
-
-
- -
- -
- -
-
-
- zip() -
-
-
- -
- -
- -
-
-
- select() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- -
-
- Mutex -
-
-
-
- Mutex() -
-
-
-
- Semaphore -
-
-
- -
-
- -
-
- -
-
-
- -
- -
- -
- -
- -
-
- await() -
-
-
-
- future() -
-
-
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
-
- JavaFx -
-
- -
-
-
- -
- - -
- -
-
-
- await() -
-
-
-
- future() -
-
-
- -
- -
- -
-
-
- delay() -
-
-
- -
-
-
- sample() -
-
-
- -
- -
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
- -
-
-
- -
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
-
- publish() -
-
-
-
- -
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
-
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
- - - -
diff --git a/kotlinx-coroutines-slf4j/index.html b/kotlinx-coroutines-slf4j/index.html index cf1bff4e7d..7d50f412ed 100644 --- a/kotlinx-coroutines-slf4j/index.html +++ b/kotlinx-coroutines-slf4j/index.html @@ -1,72 +1 @@ - - - - - kotlinx-coroutines-slf4j - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

kotlinx-coroutines-slf4j

-

Integration with SLF4J MDC.

Example

Add MDCContext to the coroutine context so that the SLF4J MDC context is captured and passed into the coroutine.

MDC.put("kotlin", "rocks") // put a value into the MDC context

launch(MDCContext()) {
logger.info { "..." } // the MDC context will contain the mapping here
}
-
-

Packages

-
-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-

Integration with SLF4J MDC.

-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/-m-d-c-context/-key/index.html b/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/-m-d-c-context/-key/index.html index 0952b3c022..3d364fb84a 100644 --- a/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/-m-d-c-context/-key/index.html +++ b/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/-m-d-c-context/-key/index.html @@ -1,58 +1 @@ - - - - - Key - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Key

-
object Key : CoroutineContext.Key<MDCContext>

Key of MDCContext in CoroutineContext.

-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/-m-d-c-context/-m-d-c-context.html b/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/-m-d-c-context/-m-d-c-context.html index cb649bf3bf..483404e474 100644 --- a/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/-m-d-c-context/-m-d-c-context.html +++ b/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/-m-d-c-context/-m-d-c-context.html @@ -1,54 +1 @@ - - - - - MDCContext - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

MDCContext

-
-
fun MDCContext(contextMap: MDCContextMap = MDC.getCopyOfContextMap())

Parameters

contextMap

the value of MDC context map. Default value is the copy of the current thread's context map that is acquired via MDC.getCopyOfContextMap.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/-m-d-c-context/context-map.html b/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/-m-d-c-context/context-map.html index 087016551f..5a05a48dcd 100644 --- a/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/-m-d-c-context/context-map.html +++ b/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/-m-d-c-context/context-map.html @@ -1,54 +1 @@ - - - - - contextMap - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

contextMap

-
-
val contextMap: MDCContextMap

The value of MDC context map.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/-m-d-c-context/index.html b/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/-m-d-c-context/index.html index 6a7c2f9b59..b5c27d6f85 100644 --- a/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/-m-d-c-context/index.html +++ b/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/-m-d-c-context/index.html @@ -1,114 +1 @@ - - - - - MDCContext - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

MDCContext

-
class MDCContext(val contextMap: MDCContextMap = MDC.getCopyOfContextMap()) : AbstractCoroutineContextElement, ThreadContextElement<MDCContextMap>

MDC context element for CoroutineContext.

Example:

MDC.put("kotlin", "rocks") // Put a value into the MDC context

launch(MDCContext()) {
logger.info { "..." } // The MDC context contains the mapping here
}

Note that you cannot update MDC context from inside the coroutine simply using MDC.put. These updates are going to be lost on the next suspension and reinstalled to the MDC context that was captured or explicitly specified in contextMap when this object was created on the next resumption. Use withContext(MDCContext()) { ... } to capture updated map of MDC keys and values for the specified block of code.

-
-
-
-
-

Parameters

-
-
contextMap

the value of MDC context map. Default value is the copy of the current thread's context map that is acquired via MDC.getCopyOfContextMap.

-
-

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
fun MDCContext(contextMap: MDCContextMap = MDC.getCopyOfContextMap())
-
-
-
-
-
-

Types

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
object Key : CoroutineContext.Key<MDCContext>
-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
val contextMap: MDCContextMap

The value of MDC context map.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/index.html b/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/index.html index e3a7fdaa18..538b02444f 100644 --- a/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/index.html +++ b/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/index.html @@ -1,91 +1 @@ - - - - - kotlinx.coroutines.slf4j - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Package kotlinx.coroutines.slf4j

-

Integration with SLF4J MDC.

-
-
-
-
-

Types

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
class MDCContext(val contextMap: MDCContextMap = MDC.getCopyOfContextMap()) : AbstractCoroutineContextElement, ThreadContextElement<MDCContextMap>

MDC context element for CoroutineContext.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
typealias MDCContextMap = Map<String, String>?

The value of MDC context map. See MDC.getCopyOfContextMap.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-slf4j/navigation.html b/kotlinx-coroutines-slf4j/navigation.html deleted file mode 100644 index be03fe14df..0000000000 --- a/kotlinx-coroutines-slf4j/navigation.html +++ /dev/null @@ -1,2047 +0,0 @@ -
- -
- -
- - - -
- -
-
- -
-
- -
-
-
- async() -
-
-
-
- await() -
-
-
- -
- - -
-
- cancel() -
-
-
- -
- - - - - - - - -
- -
-
- -
- - - - - -
- -
-
- -
- - -
- -
-
- ATOMIC -
-
-
-
- DEFAULT -
-
-
-
- LAZY -
-
-
- -
-
- - - - - -
-
- Deferred -
-
-
-
- delay() -
-
- -
- -
- -
- -
-
- -
- - -
- -
-
- -
- - -
-
- invoke() -
-
- -
-
- isActive -
-
-
- -
-
-
- Job -
-
-
-
- job -
-
-
-
- Job() -
-
-
-
- joinAll() -
-
-
-
- launch() -
-
- -
- -
- - - -
- -
- -
-
- plus() -
-
-
-
- promise() -
-
-
- -
- -
-
- Runnable -
-
-
- -
-
- -
- - - - -
- -
-
- -
- -
-
- yield() -
-
-
-
- -
-
- actor() -
-
-
- -
-
- -
-
- -
- - -
- -
- -
-
- -
-
-
- SUSPEND -
-
-
-
-
- Channel -
-
-
-
- Channel() -
-
-
- -
-
- -
- - - -
-
- consume() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- produce() -
-
-
- -
-
- -
-
- -
-
-
- ticker() -
-
-
- -
- -
-
- -
-
-
-
- toList() -
-
- -
-
- -
- -
-
-
- asFlow() -
-
-
- -
-
- -
-
-
- buffer() -
-
-
- -
-
- -
-
-
- catch() -
-
-
- -
-
-
- collect() -
-
- -
- -
-
-
- combine() -
-
- -
- -
-
- -
-
-
- count() -
-
-
- -
- - - - -
-
- drop() -
-
-
- -
-
-
- emitAll() -
-
-
- -
-
-
- filter() -
-
- -
- -
-
- -
-
-
- first() -
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
- Flow -
-
-
-
- flow() -
-
-
- -
-
-
- flowOf() -
-
-
-
- flowOn() -
-
-
-
- fold() -
-
-
- -
-
-
- last() -
-
-
- -
-
- -
-
-
- map() -
-
-
- -
-
- -
-
-
- merge() -
-
- - - - -
- -
-
-
- onEach() -
-
-
-
- onEmpty() -
-
-
-
- onStart() -
-
- -
- -
-
- -
-
-
- reduce() -
-
-
-
- retry() -
-
-
- -
-
- -
-
- -
-
-
- sample() -
-
-
-
- scan() -
-
-
- -
-
-
- shareIn() -
-
-
- -
-
- START -
-
-
-
- STOP -
-
- -
-
- -
-
-
- single() -
-
-
- -
-
-
- StateFlow -
-
-
-
- stateIn() -
-
-
-
- take() -
-
-
- -
-
- -
-
-
- toList() -
-
-
-
- toSet() -
-
-
- -
- - -
-
- update() -
-
-
- -
- -
- -
-
-
- zip() -
-
-
- -
- -
- -
-
-
- select() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- -
-
- Mutex -
-
-
-
- Mutex() -
-
-
-
- Semaphore -
-
-
- -
-
- -
-
- -
-
-
- -
- -
- -
- -
- -
-
- await() -
-
-
-
- future() -
-
-
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
-
- JavaFx -
-
- -
-
-
- -
- - -
- -
-
-
- await() -
-
-
-
- future() -
-
-
- -
- -
- -
-
-
- delay() -
-
-
- -
-
-
- sample() -
-
-
- -
- -
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
- -
-
-
- -
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
-
- publish() -
-
-
-
- -
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
-
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
- - - -
diff --git a/kotlinx-coroutines-swing/index.html b/kotlinx-coroutines-swing/index.html index b74a5f627c..05026e63af 100644 --- a/kotlinx-coroutines-swing/index.html +++ b/kotlinx-coroutines-swing/index.html @@ -1,72 +1 @@ - - - - - kotlinx-coroutines-swing - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

kotlinx-coroutines-swing

-

Provides Dispatchers.Swing context and Dispatchers.Main implementation for Swing UI applications.

Read Guide to UI programming with coroutines for tutorial on this module.

-
-

Packages

-
-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-

Provides Dispatchers.Swing context and Dispatchers.Main implementation for Swing UI applications.

-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-swing/kotlinx.coroutines.swing/-swing-dispatcher/index.html b/kotlinx-coroutines-swing/kotlinx.coroutines.swing/-swing-dispatcher/index.html index 560b70961d..cd86ef611a 100644 --- a/kotlinx-coroutines-swing/kotlinx.coroutines.swing/-swing-dispatcher/index.html +++ b/kotlinx-coroutines-swing/kotlinx.coroutines.swing/-swing-dispatcher/index.html @@ -1,58 +1 @@ - - - - - SwingDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

SwingDispatcher

-
sealed class SwingDispatcher : MainCoroutineDispatcher, Delay

Dispatcher for Swing event dispatching thread.

This class provides type-safety and a point for future extensions.

-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-swing/kotlinx.coroutines.swing/-swing.html b/kotlinx-coroutines-swing/kotlinx.coroutines.swing/-swing.html index 07946b63f1..507881881a 100644 --- a/kotlinx-coroutines-swing/kotlinx.coroutines.swing/-swing.html +++ b/kotlinx-coroutines-swing/kotlinx.coroutines.swing/-swing.html @@ -1,54 +1 @@ - - - - - Swing - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Swing

-
-
val Dispatchers.Swing: SwingDispatcher

Dispatches execution onto Swing event dispatching thread and provides native delay support.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-swing/kotlinx.coroutines.swing/index.html b/kotlinx-coroutines-swing/kotlinx.coroutines.swing/index.html index cdb13f2d53..919bd6291d 100644 --- a/kotlinx-coroutines-swing/kotlinx.coroutines.swing/index.html +++ b/kotlinx-coroutines-swing/kotlinx.coroutines.swing/index.html @@ -1,93 +1 @@ - - - - - kotlinx.coroutines.swing - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Package kotlinx.coroutines.swing

-

Provides Dispatchers.Swing context and Dispatchers.Main implementation for Swing UI applications.

-
-
-
-
-

Types

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
sealed class SwingDispatcher : MainCoroutineDispatcher, Delay

Dispatcher for Swing event dispatching thread.

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
val Dispatchers.Swing: SwingDispatcher

Dispatches execution onto Swing event dispatching thread and provides native delay support.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-swing/navigation.html b/kotlinx-coroutines-swing/navigation.html deleted file mode 100644 index be03fe14df..0000000000 --- a/kotlinx-coroutines-swing/navigation.html +++ /dev/null @@ -1,2047 +0,0 @@ -
- -
- -
- - - -
- -
-
- -
-
- -
-
-
- async() -
-
-
-
- await() -
-
-
- -
- - -
-
- cancel() -
-
-
- -
- - - - - - - - -
- -
-
- -
- - - - - -
- -
-
- -
- - -
- -
-
- ATOMIC -
-
-
-
- DEFAULT -
-
-
-
- LAZY -
-
-
- -
-
- - - - - -
-
- Deferred -
-
-
-
- delay() -
-
- -
- -
- -
- -
-
- -
- - -
- -
-
- -
- - -
-
- invoke() -
-
- -
-
- isActive -
-
-
- -
-
-
- Job -
-
-
-
- job -
-
-
-
- Job() -
-
-
-
- joinAll() -
-
-
-
- launch() -
-
- -
- -
- - - -
- -
- -
-
- plus() -
-
-
-
- promise() -
-
-
- -
- -
-
- Runnable -
-
-
- -
-
- -
- - - - -
- -
-
- -
- -
-
- yield() -
-
-
-
- -
-
- actor() -
-
-
- -
-
- -
-
- -
- - -
- -
- -
-
- -
-
-
- SUSPEND -
-
-
-
-
- Channel -
-
-
-
- Channel() -
-
-
- -
-
- -
- - - -
-
- consume() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- produce() -
-
-
- -
-
- -
-
- -
-
-
- ticker() -
-
-
- -
- -
-
- -
-
-
-
- toList() -
-
- -
-
- -
- -
-
-
- asFlow() -
-
-
- -
-
- -
-
-
- buffer() -
-
-
- -
-
- -
-
-
- catch() -
-
-
- -
-
-
- collect() -
-
- -
- -
-
-
- combine() -
-
- -
- -
-
- -
-
-
- count() -
-
-
- -
- - - - -
-
- drop() -
-
-
- -
-
-
- emitAll() -
-
-
- -
-
-
- filter() -
-
- -
- -
-
- -
-
-
- first() -
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
- Flow -
-
-
-
- flow() -
-
-
- -
-
-
- flowOf() -
-
-
-
- flowOn() -
-
-
-
- fold() -
-
-
- -
-
-
- last() -
-
-
- -
-
- -
-
-
- map() -
-
-
- -
-
- -
-
-
- merge() -
-
- - - - -
- -
-
-
- onEach() -
-
-
-
- onEmpty() -
-
-
-
- onStart() -
-
- -
- -
-
- -
-
-
- reduce() -
-
-
-
- retry() -
-
-
- -
-
- -
-
- -
-
-
- sample() -
-
-
-
- scan() -
-
-
- -
-
-
- shareIn() -
-
-
- -
-
- START -
-
-
-
- STOP -
-
- -
-
- -
-
-
- single() -
-
-
- -
-
-
- StateFlow -
-
-
-
- stateIn() -
-
-
-
- take() -
-
-
- -
-
- -
-
-
- toList() -
-
-
-
- toSet() -
-
-
- -
- - -
-
- update() -
-
-
- -
- -
- -
-
-
- zip() -
-
-
- -
- -
- -
-
-
- select() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- -
-
- Mutex -
-
-
-
- Mutex() -
-
-
-
- Semaphore -
-
-
- -
-
- -
-
- -
-
-
- -
- -
- -
- -
- -
-
- await() -
-
-
-
- future() -
-
-
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
-
- JavaFx -
-
- -
-
-
- -
- - -
- -
-
-
- await() -
-
-
-
- future() -
-
-
- -
- -
- -
-
-
- delay() -
-
-
- -
-
-
- sample() -
-
-
- -
- -
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
- -
-
-
- -
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
-
- publish() -
-
-
-
- -
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
-
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
- - - -
diff --git a/kotlinx-coroutines-test/index.html b/kotlinx-coroutines-test/index.html index f3a1fdf1fa..b75c3e83be 100644 --- a/kotlinx-coroutines-test/index.html +++ b/kotlinx-coroutines-test/index.html @@ -1,85 +1 @@ - - - - - kotlinx-coroutines-test - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

kotlinx-coroutines-test

-
-
-

Test utilities for kotlinx.coroutines.

Overview

This package provides utilities for efficiently testing coroutines.

NameDescription
runTestRuns the test code, automatically skipping delays and handling uncaught exceptions.
TestCoroutineSchedulerThe shared source of virtual time, used for controlling execution order and skipping delays.
TestScopeA CoroutineScope that integrates with runTest, providing access to TestCoroutineScheduler.
TestDispatcherA CoroutineDispatcher whose delays are controlled by a TestCoroutineScheduler.
Dispatchers.setMainMocks the main dispatcher using the provided one. If mocked with a TestDispatcher, its TestCoroutineScheduler is used everywhere by default.

Provided TestDispatcher implementations:

NameDescription
StandardTestDispatcherA simple dispatcher with no special behavior other than being linked to a TestCoroutineScheduler.
UnconfinedTestDispatcherA dispatcher that behaves like Dispatchers.Unconfined.

Using in your project

Add kotlinx-coroutines-test to your project test dependencies:

dependencies {
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.3'
}

Do not depend on this project in your main sources, all utilities here are intended and designed to be used only from tests.

Dispatchers.Main Delegation

Dispatchers.setMain will override the Main dispatcher in test scenarios. This is helpful when one wants to execute a test in situations where the platform Main dispatcher is not available, or to replace Dispatchers.Main with a testing dispatcher.

On the JVM, the ServiceLoader mechanism is responsible for overwriting Dispatchers.Main with a testable implementation, which by default will delegate its calls to the real Main dispatcher, if any.

The Main implementation can be overridden using Dispatchers.setMain method with any CoroutineDispatcher implementation, e.g.:

class SomeTest {

private val mainThreadSurrogate = newSingleThreadContext("UI thread")

@Before
fun setUp() {
Dispatchers.setMain(mainThreadSurrogate)
}

@After
fun tearDown() {
Dispatchers.resetMain() // reset the main dispatcher to the original Main dispatcher
mainThreadSurrogate.close()
}

@Test
fun testSomeUI() = runBlocking {
launch(Dispatchers.Main) { // Will be launched in the mainThreadSurrogate dispatcher
// ...
}
}
}

Calling setMain or resetMain immediately changes the Main dispatcher globally.

If Main is overridden with a TestDispatcher, then its TestCoroutineScheduler is used when new TestDispatcher or TestScope instances are created without TestCoroutineScheduler being passed as an argument.

runTest

runTest is the way to test code that involves coroutines. suspend functions can be called inside it.

IMPORTANT: in order to work with on Kotlin/JS, the result of runTest must be immediately return-ed from each test. The typical invocation of runTest thus looks like this:

@Test
fun testFoo() = runTest {
// code under test
}

In more advanced scenarios, it's possible instead to use the following form:

@Test
fun testFoo(): TestResult {
// initialize some test state
return runTest {
// code under test
}
}

runTest is similar to running the code with runBlocking on Kotlin/JVM and Kotlin/Native, or launching a new promise on Kotlin/JS. The main differences are the following:

  • The calls to delay are automatically skipped, preserving the relative execution order of the tasks. This way, it's possible to make tests finish more-or-less immediately.

  • Controlling the virtual time: in case just skipping delays is not sufficient, it's possible to more carefully guide the execution, advancing the virtual time by a duration, draining the queue of the awaiting tasks, or running the tasks scheduled at the present moment.

  • Handling uncaught exceptions spawned in the child coroutines by throwing them at the end of the test.

  • Waiting for asynchronous callbacks. Sometimes, especially when working with third-party code, it's impossible to mock all the dispatchers in use. runTest will handle the situations where some code runs in dispatchers not integrated with the test module.

Delay-skipping

To test regular suspend functions, which may have a delay, just run them inside the runTest block.

@Test
fun testFoo() = runTest { // a coroutine with an extra test control
val actual = foo()
// ...
}

suspend fun foo() {
delay(1_000) // when run in `runTest`, will finish immediately instead of delaying
// ...
}

launch and async

The coroutine dispatcher used for tests is single-threaded, meaning that the child coroutines of the runTest block will run on the thread that started the test, and will never run in parallel.

If several coroutines are waiting to be executed next, the one scheduled after the smallest delay will be chosen. The virtual time will automatically advance to the point of its resumption.

@Test
fun testWithMultipleDelays() = runTest {
launch {
delay(1_000)
println("1. $currentTime") // 1000
delay(200)
println("2. $currentTime") // 1200
delay(2_000)
println("4. $currentTime") // 3200
}
val deferred = async {
delay(3_000)
println("3. $currentTime") // 3000
delay(500)
println("5. $currentTime") // 3500
}
deferred.await()
}

Controlling the virtual time

Inside runTest, the following operations are supported:

  • currentTime gets the current virtual time.

  • runCurrent() runs the tasks that are scheduled at this point of virtual time.

  • advanceUntilIdle() runs all enqueued tasks until there are no more.

  • advanceTimeBy(timeDelta) runs the enqueued tasks until the current virtual time advances by timeDelta.

@Test
fun testFoo() = runTest {
launch {
println(1) // executes during runCurrent()
delay(1_000) // suspends until time is advanced by at least 1_000
println(2) // executes during advanceTimeBy(2_000)
delay(500) // suspends until the time is advanced by another 500 ms
println(3) // also executes during advanceTimeBy(2_000)
delay(5_000) // will suspend by another 4_500 ms
println(4) // executes during advanceUntilIdle()
}
// the child coroutine has not run yet
runCurrent()
// the child coroutine has called println(1), and is suspended on delay(1_000)
advanceTimeBy(2_000) // progress time, this will cause two calls to `delay` to resume
// the child coroutine has called println(2) and println(3) and suspends for another 4_500 virtual milliseconds
advanceUntilIdle() // will run the child coroutine to completion
assertEquals(6500, currentTime) // the child coroutine finished at virtual time of 6_500 milliseconds
}

Using multiple test dispatchers

The virtual time is controlled by an entity called the TestCoroutineScheduler, which behaves as the shared source of virtual time.

Several dispatchers can be created that use the same TestCoroutineScheduler, in which case they will share their knowledge of the virtual time.

To access the scheduler used for this test, use the TestScope.testScheduler property.

@Test
fun testWithMultipleDispatchers() = runTest {
val scheduler = testScheduler // the scheduler used for this test
val dispatcher1 = StandardTestDispatcher(scheduler, name = "IO dispatcher")
val dispatcher2 = StandardTestDispatcher(scheduler, name = "Background dispatcher")
launch(dispatcher1) {
delay(1_000)
println("1. $currentTime") // 1000
delay(200)
println("2. $currentTime") // 1200
delay(2_000)
println("4. $currentTime") // 3200
}
val deferred = async(dispatcher2) {
delay(3_000)
println("3. $currentTime") // 3000
delay(500)
println("5. $currentTime") // 3500
}
deferred.await()
}

Note: if Dispatchers.Main is replaced by a TestDispatcher, runTest will automatically use its scheduler. This is done so that there is no need to go through the ceremony of passing the correct scheduler to runTest.

Accessing the test coroutine scope

Structured concurrency ties coroutines to scopes in which they are launched. TestScope is a special coroutine scope designed for testing coroutines, and a new one is automatically created for runTest and used as the receiver for the test body.

However, it can be convenient to access a CoroutineScope before the test has started, for example, to perform mocking of some parts of the system in @BeforeTest via dependency injection. In these cases, it is possible to manually create TestScope, the scope for the test coroutines, in advance, before the test begins.

TestScope on its own does not automatically run the code launched in it. In addition, it is stateful in order to keep track of executing coroutines and uncaught exceptions. Therefore, it is important to ensure that TestScope.runTest is called eventually.

val scope = TestScope()

@BeforeTest
fun setUp() {
Dispatchers.setMain(StandardTestDispatcher(scope.testScheduler))
TestSubject.setScope(scope)
}

@AfterTest
fun tearDown() {
Dispatchers.resetMain()
TestSubject.resetScope()
}

@Test
fun testSubject() = scope.runTest {
// the receiver here is `testScope`
}

Eagerly entering launch and async blocks

Some tests only test functionality and don't particularly care about the precise order in which coroutines are dispatched. In these cases, it can be cumbersome to always call runCurrent or yield to observe the effects of the coroutines after they are launched.

If runTest executes with an UnconfinedTestDispatcher, the child coroutines launched at the top level are entered eagerly, that is, they don't go through a dispatch until the first suspension.

@Test
fun testEagerlyEnteringChildCoroutines() = runTest(UnconfinedTestDispatcher()) {
var entered = false
val deferred = CompletableDeferred<Unit>()
var completed = false
launch {
entered = true
deferred.await()
completed = true
}
assertTrue(entered) // `entered = true` already executed.
assertFalse(completed) // however, the child coroutine then suspended, so it is enqueued.
deferred.complete(Unit) // resume the coroutine.
assertTrue(completed) // now the child coroutine is immediately completed.
}

If this behavior is desirable, but some parts of the test still require accurate dispatching, for example, to ensure that the code executes on the correct thread, then simply launch a new coroutine with the StandardTestDispatcher.

@Test
fun testEagerlyEnteringSomeChildCoroutines() = runTest(UnconfinedTestDispatcher()) {
var entered1 = false
launch {
entered1 = true
}
assertTrue(entered1) // `entered1 = true` already executed

var entered2 = false
launch(StandardTestDispatcher(testScheduler)) {
// this block and every coroutine launched inside it will explicitly go through the needed dispatches
entered2 = true
}
assertFalse(entered2)
runCurrent() // need to explicitly run the dispatched continuation
assertTrue(entered2)
}

Using withTimeout inside runTest

Timeouts are also susceptible to time control, so the code below will immediately finish.

@Test
fun testFooWithTimeout() = runTest {
assertFailsWith<TimeoutCancellationException> {
withTimeout(1_000) {
delay(999)
delay(2)
println("this won't be reached")
}
}
}

Virtual time support with other dispatchers

Calls to withContext(Dispatchers.IO), withContext(Dispatchers.Default) ,and withContext(Dispatchers.Main) are common in coroutines-based code bases. Unfortunately, just executing code in a test will not lead to these dispatchers using the virtual time source, so delays will not be skipped in them.

suspend fun veryExpensiveFunction() = withContext(Dispatchers.Default) {
delay(1_000)
1
}

fun testExpensiveFunction() = runTest {
val result = veryExpensiveFunction() // will take a whole real-time second to execute
// the virtual time at this point is still 0
}

Tests should, when possible, replace these dispatchers with a TestDispatcher if the withContext calls delay in the function under test. For example, veryExpensiveFunction above should allow mocking with a TestDispatcher using either dependency injection, a service locator, or a default parameter, if it is to be used with virtual time.

Status of the API

This API is experimental and it is may change before migrating out of experimental (while it is marked as @ExperimentalCoroutinesApi). Changes during experimental may have deprecation applied when possible, but it is not advised to use the API in stable code before it leaves experimental due to possible breaking changes.

If you have any suggestions for improvements to this experimental API please share them on the issue tracker.

Test utilities for kotlinx.coroutines.

Overview

This package provides utilities for efficiently testing coroutines.

NameDescription
runTestRuns the test code, automatically skipping delays and handling uncaught exceptions.
TestCoroutineSchedulerThe shared source of virtual time, used for controlling execution order and skipping delays.
TestScopeA CoroutineScope that integrates with runTest, providing access to TestCoroutineScheduler.
TestDispatcherA CoroutineDispatcher whose delays are controlled by a TestCoroutineScheduler.
Dispatchers.setMainMocks the main dispatcher using the provided one. If mocked with a TestDispatcher, its TestCoroutineScheduler is used everywhere by default.

Provided TestDispatcher implementations:

NameDescription
StandardTestDispatcherA simple dispatcher with no special behavior other than being linked to a TestCoroutineScheduler.
UnconfinedTestDispatcherA dispatcher that behaves like Dispatchers.Unconfined.

Using in your project

Add kotlinx-coroutines-test to your project test dependencies:

dependencies {
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.3'
}

Do not depend on this project in your main sources, all utilities here are intended and designed to be used only from tests.

Dispatchers.Main Delegation

Dispatchers.setMain will override the Main dispatcher in test scenarios. This is helpful when one wants to execute a test in situations where the platform Main dispatcher is not available, or to replace Dispatchers.Main with a testing dispatcher.

On the JVM, the ServiceLoader mechanism is responsible for overwriting Dispatchers.Main with a testable implementation, which by default will delegate its calls to the real Main dispatcher, if any.

The Main implementation can be overridden using Dispatchers.setMain method with any CoroutineDispatcher implementation, e.g.:

class SomeTest {

private val mainThreadSurrogate = newSingleThreadContext("UI thread")

@Before
fun setUp() {
Dispatchers.setMain(mainThreadSurrogate)
}

@After
fun tearDown() {
Dispatchers.resetMain() // reset the main dispatcher to the original Main dispatcher
mainThreadSurrogate.close()
}

@Test
fun testSomeUI() = runBlocking {
launch(Dispatchers.Main) { // Will be launched in the mainThreadSurrogate dispatcher
// ...
}
}
}

Calling setMain or resetMain immediately changes the Main dispatcher globally.

If Main is overridden with a TestDispatcher, then its TestCoroutineScheduler is used when new TestDispatcher or TestScope instances are created without TestCoroutineScheduler being passed as an argument.

runTest

runTest is the way to test code that involves coroutines. suspend functions can be called inside it.

IMPORTANT: in order to work with on Kotlin/JS, the result of runTest must be immediately return-ed from each test. The typical invocation of runTest thus looks like this:

@Test
fun testFoo() = runTest {
// code under test
}

In more advanced scenarios, it's possible instead to use the following form:

@Test
fun testFoo(): TestResult {
// initialize some test state
return runTest {
// code under test
}
}

runTest is similar to running the code with runBlocking on Kotlin/JVM and Kotlin/Native, or launching a new promise on Kotlin/JS. The main differences are the following:

  • The calls to delay are automatically skipped, preserving the relative execution order of the tasks. This way, it's possible to make tests finish more-or-less immediately.

  • Controlling the virtual time: in case just skipping delays is not sufficient, it's possible to more carefully guide the execution, advancing the virtual time by a duration, draining the queue of the awaiting tasks, or running the tasks scheduled at the present moment.

  • Handling uncaught exceptions spawned in the child coroutines by throwing them at the end of the test.

  • Waiting for asynchronous callbacks. Sometimes, especially when working with third-party code, it's impossible to mock all the dispatchers in use. runTest will handle the situations where some code runs in dispatchers not integrated with the test module.

Delay-skipping

To test regular suspend functions, which may have a delay, just run them inside the runTest block.

@Test
fun testFoo() = runTest { // a coroutine with an extra test control
val actual = foo()
// ...
}

suspend fun foo() {
delay(1_000) // when run in `runTest`, will finish immediately instead of delaying
// ...
}

launch and async

The coroutine dispatcher used for tests is single-threaded, meaning that the child coroutines of the runTest block will run on the thread that started the test, and will never run in parallel.

If several coroutines are waiting to be executed next, the one scheduled after the smallest delay will be chosen. The virtual time will automatically advance to the point of its resumption.

@Test
fun testWithMultipleDelays() = runTest {
launch {
delay(1_000)
println("1. $currentTime") // 1000
delay(200)
println("2. $currentTime") // 1200
delay(2_000)
println("4. $currentTime") // 3200
}
val deferred = async {
delay(3_000)
println("3. $currentTime") // 3000
delay(500)
println("5. $currentTime") // 3500
}
deferred.await()
}

Controlling the virtual time

Inside runTest, the following operations are supported:

  • currentTime gets the current virtual time.

  • runCurrent() runs the tasks that are scheduled at this point of virtual time.

  • advanceUntilIdle() runs all enqueued tasks until there are no more.

  • advanceTimeBy(timeDelta) runs the enqueued tasks until the current virtual time advances by timeDelta.

@Test
fun testFoo() = runTest {
launch {
println(1) // executes during runCurrent()
delay(1_000) // suspends until time is advanced by at least 1_000
println(2) // executes during advanceTimeBy(2_000)
delay(500) // suspends until the time is advanced by another 500 ms
println(3) // also executes during advanceTimeBy(2_000)
delay(5_000) // will suspend by another 4_500 ms
println(4) // executes during advanceUntilIdle()
}
// the child coroutine has not run yet
runCurrent()
// the child coroutine has called println(1), and is suspended on delay(1_000)
advanceTimeBy(2_000) // progress time, this will cause two calls to `delay` to resume
// the child coroutine has called println(2) and println(3) and suspends for another 4_500 virtual milliseconds
advanceUntilIdle() // will run the child coroutine to completion
assertEquals(6500, currentTime) // the child coroutine finished at virtual time of 6_500 milliseconds
}

Using multiple test dispatchers

The virtual time is controlled by an entity called the TestCoroutineScheduler, which behaves as the shared source of virtual time.

Several dispatchers can be created that use the same TestCoroutineScheduler, in which case they will share their knowledge of the virtual time.

To access the scheduler used for this test, use the TestScope.testScheduler property.

@Test
fun testWithMultipleDispatchers() = runTest {
val scheduler = testScheduler // the scheduler used for this test
val dispatcher1 = StandardTestDispatcher(scheduler, name = "IO dispatcher")
val dispatcher2 = StandardTestDispatcher(scheduler, name = "Background dispatcher")
launch(dispatcher1) {
delay(1_000)
println("1. $currentTime") // 1000
delay(200)
println("2. $currentTime") // 1200
delay(2_000)
println("4. $currentTime") // 3200
}
val deferred = async(dispatcher2) {
delay(3_000)
println("3. $currentTime") // 3000
delay(500)
println("5. $currentTime") // 3500
}
deferred.await()
}

Note: if Dispatchers.Main is replaced by a TestDispatcher, runTest will automatically use its scheduler. This is done so that there is no need to go through the ceremony of passing the correct scheduler to runTest.

Accessing the test coroutine scope

Structured concurrency ties coroutines to scopes in which they are launched. TestScope is a special coroutine scope designed for testing coroutines, and a new one is automatically created for runTest and used as the receiver for the test body.

However, it can be convenient to access a CoroutineScope before the test has started, for example, to perform mocking of some parts of the system in @BeforeTest via dependency injection. In these cases, it is possible to manually create TestScope, the scope for the test coroutines, in advance, before the test begins.

TestScope on its own does not automatically run the code launched in it. In addition, it is stateful in order to keep track of executing coroutines and uncaught exceptions. Therefore, it is important to ensure that TestScope.runTest is called eventually.

val scope = TestScope()

@BeforeTest
fun setUp() {
Dispatchers.setMain(StandardTestDispatcher(scope.testScheduler))
TestSubject.setScope(scope)
}

@AfterTest
fun tearDown() {
Dispatchers.resetMain()
TestSubject.resetScope()
}

@Test
fun testSubject() = scope.runTest {
// the receiver here is `testScope`
}

Eagerly entering launch and async blocks

Some tests only test functionality and don't particularly care about the precise order in which coroutines are dispatched. In these cases, it can be cumbersome to always call runCurrent or yield to observe the effects of the coroutines after they are launched.

If runTest executes with an UnconfinedTestDispatcher, the child coroutines launched at the top level are entered eagerly, that is, they don't go through a dispatch until the first suspension.

@Test
fun testEagerlyEnteringChildCoroutines() = runTest(UnconfinedTestDispatcher()) {
var entered = false
val deferred = CompletableDeferred<Unit>()
var completed = false
launch {
entered = true
deferred.await()
completed = true
}
assertTrue(entered) // `entered = true` already executed.
assertFalse(completed) // however, the child coroutine then suspended, so it is enqueued.
deferred.complete(Unit) // resume the coroutine.
assertTrue(completed) // now the child coroutine is immediately completed.
}

If this behavior is desirable, but some parts of the test still require accurate dispatching, for example, to ensure that the code executes on the correct thread, then simply launch a new coroutine with the StandardTestDispatcher.

@Test
fun testEagerlyEnteringSomeChildCoroutines() = runTest(UnconfinedTestDispatcher()) {
var entered1 = false
launch {
entered1 = true
}
assertTrue(entered1) // `entered1 = true` already executed

var entered2 = false
launch(StandardTestDispatcher(testScheduler)) {
// this block and every coroutine launched inside it will explicitly go through the needed dispatches
entered2 = true
}
assertFalse(entered2)
runCurrent() // need to explicitly run the dispatched continuation
assertTrue(entered2)
}

Using withTimeout inside runTest

Timeouts are also susceptible to time control, so the code below will immediately finish.

@Test
fun testFooWithTimeout() = runTest {
assertFailsWith<TimeoutCancellationException> {
withTimeout(1_000) {
delay(999)
delay(2)
println("this won't be reached")
}
}
}

Virtual time support with other dispatchers

Calls to withContext(Dispatchers.IO), withContext(Dispatchers.Default) ,and withContext(Dispatchers.Main) are common in coroutines-based code bases. Unfortunately, just executing code in a test will not lead to these dispatchers using the virtual time source, so delays will not be skipped in them.

suspend fun veryExpensiveFunction() = withContext(Dispatchers.Default) {
delay(1_000)
1
}

fun testExpensiveFunction() = runTest {
val result = veryExpensiveFunction() // will take a whole real-time second to execute
// the virtual time at this point is still 0
}

Tests should, when possible, replace these dispatchers with a TestDispatcher if the withContext calls delay in the function under test. For example, veryExpensiveFunction above should allow mocking with a TestDispatcher using either dependency injection, a service locator, or a default parameter, if it is to be used with virtual time.

Status of the API

This API is experimental and it is may change before migrating out of experimental (while it is marked as @ExperimentalCoroutinesApi). Changes during experimental may have deprecation applied when possible, but it is not advised to use the API in stable code before it leaves experimental due to possible breaking changes.

If you have any suggestions for improvements to this experimental API please share them on the issue tracker.

Test utilities for kotlinx.coroutines.

Overview

This package provides utilities for efficiently testing coroutines.

NameDescription
runTestRuns the test code, automatically skipping delays and handling uncaught exceptions.
TestCoroutineSchedulerThe shared source of virtual time, used for controlling execution order and skipping delays.
TestScopeA CoroutineScope that integrates with runTest, providing access to TestCoroutineScheduler.
TestDispatcherA CoroutineDispatcher whose delays are controlled by a TestCoroutineScheduler.
Dispatchers.setMainMocks the main dispatcher using the provided one. If mocked with a TestDispatcher, its TestCoroutineScheduler is used everywhere by default.

Provided TestDispatcher implementations:

NameDescription
StandardTestDispatcherA simple dispatcher with no special behavior other than being linked to a TestCoroutineScheduler.
UnconfinedTestDispatcherA dispatcher that behaves like Dispatchers.Unconfined.

Using in your project

Add kotlinx-coroutines-test to your project test dependencies:

dependencies {
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.3'
}

Do not depend on this project in your main sources, all utilities here are intended and designed to be used only from tests.

Dispatchers.Main Delegation

Dispatchers.setMain will override the Main dispatcher in test scenarios. This is helpful when one wants to execute a test in situations where the platform Main dispatcher is not available, or to replace Dispatchers.Main with a testing dispatcher.

On the JVM, the ServiceLoader mechanism is responsible for overwriting Dispatchers.Main with a testable implementation, which by default will delegate its calls to the real Main dispatcher, if any.

The Main implementation can be overridden using Dispatchers.setMain method with any CoroutineDispatcher implementation, e.g.:

class SomeTest {

private val mainThreadSurrogate = newSingleThreadContext("UI thread")

@Before
fun setUp() {
Dispatchers.setMain(mainThreadSurrogate)
}

@After
fun tearDown() {
Dispatchers.resetMain() // reset the main dispatcher to the original Main dispatcher
mainThreadSurrogate.close()
}

@Test
fun testSomeUI() = runBlocking {
launch(Dispatchers.Main) { // Will be launched in the mainThreadSurrogate dispatcher
// ...
}
}
}

Calling setMain or resetMain immediately changes the Main dispatcher globally.

If Main is overridden with a TestDispatcher, then its TestCoroutineScheduler is used when new TestDispatcher or TestScope instances are created without TestCoroutineScheduler being passed as an argument.

runTest

runTest is the way to test code that involves coroutines. suspend functions can be called inside it.

IMPORTANT: in order to work with on Kotlin/JS, the result of runTest must be immediately return-ed from each test. The typical invocation of runTest thus looks like this:

@Test
fun testFoo() = runTest {
// code under test
}

In more advanced scenarios, it's possible instead to use the following form:

@Test
fun testFoo(): TestResult {
// initialize some test state
return runTest {
// code under test
}
}

runTest is similar to running the code with runBlocking on Kotlin/JVM and Kotlin/Native, or launching a new promise on Kotlin/JS. The main differences are the following:

  • The calls to delay are automatically skipped, preserving the relative execution order of the tasks. This way, it's possible to make tests finish more-or-less immediately.

  • Controlling the virtual time: in case just skipping delays is not sufficient, it's possible to more carefully guide the execution, advancing the virtual time by a duration, draining the queue of the awaiting tasks, or running the tasks scheduled at the present moment.

  • Handling uncaught exceptions spawned in the child coroutines by throwing them at the end of the test.

  • Waiting for asynchronous callbacks. Sometimes, especially when working with third-party code, it's impossible to mock all the dispatchers in use. runTest will handle the situations where some code runs in dispatchers not integrated with the test module.

Delay-skipping

To test regular suspend functions, which may have a delay, just run them inside the runTest block.

@Test
fun testFoo() = runTest { // a coroutine with an extra test control
val actual = foo()
// ...
}

suspend fun foo() {
delay(1_000) // when run in `runTest`, will finish immediately instead of delaying
// ...
}

launch and async

The coroutine dispatcher used for tests is single-threaded, meaning that the child coroutines of the runTest block will run on the thread that started the test, and will never run in parallel.

If several coroutines are waiting to be executed next, the one scheduled after the smallest delay will be chosen. The virtual time will automatically advance to the point of its resumption.

@Test
fun testWithMultipleDelays() = runTest {
launch {
delay(1_000)
println("1. $currentTime") // 1000
delay(200)
println("2. $currentTime") // 1200
delay(2_000)
println("4. $currentTime") // 3200
}
val deferred = async {
delay(3_000)
println("3. $currentTime") // 3000
delay(500)
println("5. $currentTime") // 3500
}
deferred.await()
}

Controlling the virtual time

Inside runTest, the following operations are supported:

  • currentTime gets the current virtual time.

  • runCurrent() runs the tasks that are scheduled at this point of virtual time.

  • advanceUntilIdle() runs all enqueued tasks until there are no more.

  • advanceTimeBy(timeDelta) runs the enqueued tasks until the current virtual time advances by timeDelta.

@Test
fun testFoo() = runTest {
launch {
println(1) // executes during runCurrent()
delay(1_000) // suspends until time is advanced by at least 1_000
println(2) // executes during advanceTimeBy(2_000)
delay(500) // suspends until the time is advanced by another 500 ms
println(3) // also executes during advanceTimeBy(2_000)
delay(5_000) // will suspend by another 4_500 ms
println(4) // executes during advanceUntilIdle()
}
// the child coroutine has not run yet
runCurrent()
// the child coroutine has called println(1), and is suspended on delay(1_000)
advanceTimeBy(2_000) // progress time, this will cause two calls to `delay` to resume
// the child coroutine has called println(2) and println(3) and suspends for another 4_500 virtual milliseconds
advanceUntilIdle() // will run the child coroutine to completion
assertEquals(6500, currentTime) // the child coroutine finished at virtual time of 6_500 milliseconds
}

Using multiple test dispatchers

The virtual time is controlled by an entity called the TestCoroutineScheduler, which behaves as the shared source of virtual time.

Several dispatchers can be created that use the same TestCoroutineScheduler, in which case they will share their knowledge of the virtual time.

To access the scheduler used for this test, use the TestScope.testScheduler property.

@Test
fun testWithMultipleDispatchers() = runTest {
val scheduler = testScheduler // the scheduler used for this test
val dispatcher1 = StandardTestDispatcher(scheduler, name = "IO dispatcher")
val dispatcher2 = StandardTestDispatcher(scheduler, name = "Background dispatcher")
launch(dispatcher1) {
delay(1_000)
println("1. $currentTime") // 1000
delay(200)
println("2. $currentTime") // 1200
delay(2_000)
println("4. $currentTime") // 3200
}
val deferred = async(dispatcher2) {
delay(3_000)
println("3. $currentTime") // 3000
delay(500)
println("5. $currentTime") // 3500
}
deferred.await()
}

Note: if Dispatchers.Main is replaced by a TestDispatcher, runTest will automatically use its scheduler. This is done so that there is no need to go through the ceremony of passing the correct scheduler to runTest.

Accessing the test coroutine scope

Structured concurrency ties coroutines to scopes in which they are launched. TestScope is a special coroutine scope designed for testing coroutines, and a new one is automatically created for runTest and used as the receiver for the test body.

However, it can be convenient to access a CoroutineScope before the test has started, for example, to perform mocking of some parts of the system in @BeforeTest via dependency injection. In these cases, it is possible to manually create TestScope, the scope for the test coroutines, in advance, before the test begins.

TestScope on its own does not automatically run the code launched in it. In addition, it is stateful in order to keep track of executing coroutines and uncaught exceptions. Therefore, it is important to ensure that TestScope.runTest is called eventually.

val scope = TestScope()

@BeforeTest
fun setUp() {
Dispatchers.setMain(StandardTestDispatcher(scope.testScheduler))
TestSubject.setScope(scope)
}

@AfterTest
fun tearDown() {
Dispatchers.resetMain()
TestSubject.resetScope()
}

@Test
fun testSubject() = scope.runTest {
// the receiver here is `testScope`
}

Eagerly entering launch and async blocks

Some tests only test functionality and don't particularly care about the precise order in which coroutines are dispatched. In these cases, it can be cumbersome to always call runCurrent or yield to observe the effects of the coroutines after they are launched.

If runTest executes with an UnconfinedTestDispatcher, the child coroutines launched at the top level are entered eagerly, that is, they don't go through a dispatch until the first suspension.

@Test
fun testEagerlyEnteringChildCoroutines() = runTest(UnconfinedTestDispatcher()) {
var entered = false
val deferred = CompletableDeferred<Unit>()
var completed = false
launch {
entered = true
deferred.await()
completed = true
}
assertTrue(entered) // `entered = true` already executed.
assertFalse(completed) // however, the child coroutine then suspended, so it is enqueued.
deferred.complete(Unit) // resume the coroutine.
assertTrue(completed) // now the child coroutine is immediately completed.
}

If this behavior is desirable, but some parts of the test still require accurate dispatching, for example, to ensure that the code executes on the correct thread, then simply launch a new coroutine with the StandardTestDispatcher.

@Test
fun testEagerlyEnteringSomeChildCoroutines() = runTest(UnconfinedTestDispatcher()) {
var entered1 = false
launch {
entered1 = true
}
assertTrue(entered1) // `entered1 = true` already executed

var entered2 = false
launch(StandardTestDispatcher(testScheduler)) {
// this block and every coroutine launched inside it will explicitly go through the needed dispatches
entered2 = true
}
assertFalse(entered2)
runCurrent() // need to explicitly run the dispatched continuation
assertTrue(entered2)
}

Using withTimeout inside runTest

Timeouts are also susceptible to time control, so the code below will immediately finish.

@Test
fun testFooWithTimeout() = runTest {
assertFailsWith<TimeoutCancellationException> {
withTimeout(1_000) {
delay(999)
delay(2)
println("this won't be reached")
}
}
}

Virtual time support with other dispatchers

Calls to withContext(Dispatchers.IO), withContext(Dispatchers.Default) ,and withContext(Dispatchers.Main) are common in coroutines-based code bases. Unfortunately, just executing code in a test will not lead to these dispatchers using the virtual time source, so delays will not be skipped in them.

suspend fun veryExpensiveFunction() = withContext(Dispatchers.Default) {
delay(1_000)
1
}

fun testExpensiveFunction() = runTest {
val result = veryExpensiveFunction() // will take a whole real-time second to execute
// the virtual time at this point is still 0
}

Tests should, when possible, replace these dispatchers with a TestDispatcher if the withContext calls delay in the function under test. For example, veryExpensiveFunction above should allow mocking with a TestDispatcher using either dependency injection, a service locator, or a default parameter, if it is to be used with virtual time.

Status of the API

This API is experimental and it is may change before migrating out of experimental (while it is marked as @ExperimentalCoroutinesApi). Changes during experimental may have deprecation applied when possible, but it is not advised to use the API in stable code before it leaves experimental due to possible breaking changes.

If you have any suggestions for improvements to this experimental API please share them on the issue tracker.

Test utilities for kotlinx.coroutines.

Overview

This package provides utilities for efficiently testing coroutines.

NameDescription
runTestRuns the test code, automatically skipping delays and handling uncaught exceptions.
TestCoroutineSchedulerThe shared source of virtual time, used for controlling execution order and skipping delays.
TestScopeA CoroutineScope that integrates with runTest, providing access to TestCoroutineScheduler.
TestDispatcherA CoroutineDispatcher whose delays are controlled by a TestCoroutineScheduler.
Dispatchers.setMainMocks the main dispatcher using the provided one. If mocked with a TestDispatcher, its TestCoroutineScheduler is used everywhere by default.

Provided TestDispatcher implementations:

NameDescription
StandardTestDispatcherA simple dispatcher with no special behavior other than being linked to a TestCoroutineScheduler.
UnconfinedTestDispatcherA dispatcher that behaves like Dispatchers.Unconfined.

Using in your project

Add kotlinx-coroutines-test to your project test dependencies:

dependencies {
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.3'
}

Do not depend on this project in your main sources, all utilities here are intended and designed to be used only from tests.

Dispatchers.Main Delegation

Dispatchers.setMain will override the Main dispatcher in test scenarios. This is helpful when one wants to execute a test in situations where the platform Main dispatcher is not available, or to replace Dispatchers.Main with a testing dispatcher.

On the JVM, the ServiceLoader mechanism is responsible for overwriting Dispatchers.Main with a testable implementation, which by default will delegate its calls to the real Main dispatcher, if any.

The Main implementation can be overridden using Dispatchers.setMain method with any CoroutineDispatcher implementation, e.g.:

class SomeTest {

private val mainThreadSurrogate = newSingleThreadContext("UI thread")

@Before
fun setUp() {
Dispatchers.setMain(mainThreadSurrogate)
}

@After
fun tearDown() {
Dispatchers.resetMain() // reset the main dispatcher to the original Main dispatcher
mainThreadSurrogate.close()
}

@Test
fun testSomeUI() = runBlocking {
launch(Dispatchers.Main) { // Will be launched in the mainThreadSurrogate dispatcher
// ...
}
}
}

Calling setMain or resetMain immediately changes the Main dispatcher globally.

If Main is overridden with a TestDispatcher, then its TestCoroutineScheduler is used when new TestDispatcher or TestScope instances are created without TestCoroutineScheduler being passed as an argument.

runTest

runTest is the way to test code that involves coroutines. suspend functions can be called inside it.

IMPORTANT: in order to work with on Kotlin/JS, the result of runTest must be immediately return-ed from each test. The typical invocation of runTest thus looks like this:

@Test
fun testFoo() = runTest {
// code under test
}

In more advanced scenarios, it's possible instead to use the following form:

@Test
fun testFoo(): TestResult {
// initialize some test state
return runTest {
// code under test
}
}

runTest is similar to running the code with runBlocking on Kotlin/JVM and Kotlin/Native, or launching a new promise on Kotlin/JS. The main differences are the following:

  • The calls to delay are automatically skipped, preserving the relative execution order of the tasks. This way, it's possible to make tests finish more-or-less immediately.

  • Controlling the virtual time: in case just skipping delays is not sufficient, it's possible to more carefully guide the execution, advancing the virtual time by a duration, draining the queue of the awaiting tasks, or running the tasks scheduled at the present moment.

  • Handling uncaught exceptions spawned in the child coroutines by throwing them at the end of the test.

  • Waiting for asynchronous callbacks. Sometimes, especially when working with third-party code, it's impossible to mock all the dispatchers in use. runTest will handle the situations where some code runs in dispatchers not integrated with the test module.

Delay-skipping

To test regular suspend functions, which may have a delay, just run them inside the runTest block.

@Test
fun testFoo() = runTest { // a coroutine with an extra test control
val actual = foo()
// ...
}

suspend fun foo() {
delay(1_000) // when run in `runTest`, will finish immediately instead of delaying
// ...
}

launch and async

The coroutine dispatcher used for tests is single-threaded, meaning that the child coroutines of the runTest block will run on the thread that started the test, and will never run in parallel.

If several coroutines are waiting to be executed next, the one scheduled after the smallest delay will be chosen. The virtual time will automatically advance to the point of its resumption.

@Test
fun testWithMultipleDelays() = runTest {
launch {
delay(1_000)
println("1. $currentTime") // 1000
delay(200)
println("2. $currentTime") // 1200
delay(2_000)
println("4. $currentTime") // 3200
}
val deferred = async {
delay(3_000)
println("3. $currentTime") // 3000
delay(500)
println("5. $currentTime") // 3500
}
deferred.await()
}

Controlling the virtual time

Inside runTest, the following operations are supported:

  • currentTime gets the current virtual time.

  • runCurrent() runs the tasks that are scheduled at this point of virtual time.

  • advanceUntilIdle() runs all enqueued tasks until there are no more.

  • advanceTimeBy(timeDelta) runs the enqueued tasks until the current virtual time advances by timeDelta.

@Test
fun testFoo() = runTest {
launch {
println(1) // executes during runCurrent()
delay(1_000) // suspends until time is advanced by at least 1_000
println(2) // executes during advanceTimeBy(2_000)
delay(500) // suspends until the time is advanced by another 500 ms
println(3) // also executes during advanceTimeBy(2_000)
delay(5_000) // will suspend by another 4_500 ms
println(4) // executes during advanceUntilIdle()
}
// the child coroutine has not run yet
runCurrent()
// the child coroutine has called println(1), and is suspended on delay(1_000)
advanceTimeBy(2_000) // progress time, this will cause two calls to `delay` to resume
// the child coroutine has called println(2) and println(3) and suspends for another 4_500 virtual milliseconds
advanceUntilIdle() // will run the child coroutine to completion
assertEquals(6500, currentTime) // the child coroutine finished at virtual time of 6_500 milliseconds
}

Using multiple test dispatchers

The virtual time is controlled by an entity called the TestCoroutineScheduler, which behaves as the shared source of virtual time.

Several dispatchers can be created that use the same TestCoroutineScheduler, in which case they will share their knowledge of the virtual time.

To access the scheduler used for this test, use the TestScope.testScheduler property.

@Test
fun testWithMultipleDispatchers() = runTest {
val scheduler = testScheduler // the scheduler used for this test
val dispatcher1 = StandardTestDispatcher(scheduler, name = "IO dispatcher")
val dispatcher2 = StandardTestDispatcher(scheduler, name = "Background dispatcher")
launch(dispatcher1) {
delay(1_000)
println("1. $currentTime") // 1000
delay(200)
println("2. $currentTime") // 1200
delay(2_000)
println("4. $currentTime") // 3200
}
val deferred = async(dispatcher2) {
delay(3_000)
println("3. $currentTime") // 3000
delay(500)
println("5. $currentTime") // 3500
}
deferred.await()
}

Note: if Dispatchers.Main is replaced by a TestDispatcher, runTest will automatically use its scheduler. This is done so that there is no need to go through the ceremony of passing the correct scheduler to runTest.

Accessing the test coroutine scope

Structured concurrency ties coroutines to scopes in which they are launched. TestScope is a special coroutine scope designed for testing coroutines, and a new one is automatically created for runTest and used as the receiver for the test body.

However, it can be convenient to access a CoroutineScope before the test has started, for example, to perform mocking of some parts of the system in @BeforeTest via dependency injection. In these cases, it is possible to manually create TestScope, the scope for the test coroutines, in advance, before the test begins.

TestScope on its own does not automatically run the code launched in it. In addition, it is stateful in order to keep track of executing coroutines and uncaught exceptions. Therefore, it is important to ensure that TestScope.runTest is called eventually.

val scope = TestScope()

@BeforeTest
fun setUp() {
Dispatchers.setMain(StandardTestDispatcher(scope.testScheduler))
TestSubject.setScope(scope)
}

@AfterTest
fun tearDown() {
Dispatchers.resetMain()
TestSubject.resetScope()
}

@Test
fun testSubject() = scope.runTest {
// the receiver here is `testScope`
}

Eagerly entering launch and async blocks

Some tests only test functionality and don't particularly care about the precise order in which coroutines are dispatched. In these cases, it can be cumbersome to always call runCurrent or yield to observe the effects of the coroutines after they are launched.

If runTest executes with an UnconfinedTestDispatcher, the child coroutines launched at the top level are entered eagerly, that is, they don't go through a dispatch until the first suspension.

@Test
fun testEagerlyEnteringChildCoroutines() = runTest(UnconfinedTestDispatcher()) {
var entered = false
val deferred = CompletableDeferred<Unit>()
var completed = false
launch {
entered = true
deferred.await()
completed = true
}
assertTrue(entered) // `entered = true` already executed.
assertFalse(completed) // however, the child coroutine then suspended, so it is enqueued.
deferred.complete(Unit) // resume the coroutine.
assertTrue(completed) // now the child coroutine is immediately completed.
}

If this behavior is desirable, but some parts of the test still require accurate dispatching, for example, to ensure that the code executes on the correct thread, then simply launch a new coroutine with the StandardTestDispatcher.

@Test
fun testEagerlyEnteringSomeChildCoroutines() = runTest(UnconfinedTestDispatcher()) {
var entered1 = false
launch {
entered1 = true
}
assertTrue(entered1) // `entered1 = true` already executed

var entered2 = false
launch(StandardTestDispatcher(testScheduler)) {
// this block and every coroutine launched inside it will explicitly go through the needed dispatches
entered2 = true
}
assertFalse(entered2)
runCurrent() // need to explicitly run the dispatched continuation
assertTrue(entered2)
}

Using withTimeout inside runTest

Timeouts are also susceptible to time control, so the code below will immediately finish.

@Test
fun testFooWithTimeout() = runTest {
assertFailsWith<TimeoutCancellationException> {
withTimeout(1_000) {
delay(999)
delay(2)
println("this won't be reached")
}
}
}

Virtual time support with other dispatchers

Calls to withContext(Dispatchers.IO), withContext(Dispatchers.Default) ,and withContext(Dispatchers.Main) are common in coroutines-based code bases. Unfortunately, just executing code in a test will not lead to these dispatchers using the virtual time source, so delays will not be skipped in them.

suspend fun veryExpensiveFunction() = withContext(Dispatchers.Default) {
delay(1_000)
1
}

fun testExpensiveFunction() = runTest {
val result = veryExpensiveFunction() // will take a whole real-time second to execute
// the virtual time at this point is still 0
}

Tests should, when possible, replace these dispatchers with a TestDispatcher if the withContext calls delay in the function under test. For example, veryExpensiveFunction above should allow mocking with a TestDispatcher using either dependency injection, a service locator, or a default parameter, if it is to be used with virtual time.

Status of the API

This API is experimental and it is may change before migrating out of experimental (while it is marked as @ExperimentalCoroutinesApi). Changes during experimental may have deprecation applied when possible, but it is not advised to use the API in stable code before it leaves experimental due to possible breaking changes.

If you have any suggestions for improvements to this experimental API please share them on the issue tracker.

-
-

Packages

-
-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
common
-
js
- -
native
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/advance-time-by.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/advance-time-by.html index c7939c2228..d98508a7f9 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/advance-time-by.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/advance-time-by.html @@ -1,59 +1 @@ - - - - - advanceTimeBy - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

advanceTimeBy

-
-
-
-
abstract fun advanceTimeBy(delayTimeMillis: Long): Long

Moves the Dispatcher's virtual clock forward by a specified amount of time.

The amount the clock is progressed may be larger than the requested delayTimeMillis if the code under test uses blocking coroutines.

The virtual clock time will advance once for each delay resumed until the next delay exceeds the requested delayTimeMills. In the following test, the virtual time will progress by 2_000 then 1 to resume three different calls to delay.

@Test
fun advanceTimeTest() = runBlockingTest {
foo()
advanceTimeBy(2_000) // advanceTimeBy(2_000) will progress through the first two delays
// virtual time is 2_000, next resume is at 2_001
advanceTimeBy(2) // progress through the last delay of 501 (note 500ms were already advanced)
// virtual time is 2_0002
}

fun CoroutineScope.foo() {
launch {
delay(1_000) // advanceTimeBy(2_000) will progress through this delay (resume @ virtual time 1_000)
// virtual time is 1_000
delay(500) // advanceTimeBy(2_000) will progress through this delay (resume @ virtual time 1_500)
// virtual time is 1_500
delay(501) // advanceTimeBy(2_000) will not progress through this delay (resume @ virtual time 2_001)
// virtual time is 2_001
}
}

Return

The amount of delay-time that this Dispatcher's clock has been forwarded.

Parameters

delayTimeMillis

The amount of time to move the CoroutineContext's clock forward.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/advance-until-idle.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/advance-until-idle.html index 51dcdc6dca..11aac19d7e 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/advance-until-idle.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/advance-until-idle.html @@ -1,59 +1 @@ - - - - - advanceUntilIdle - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

advanceUntilIdle

-
-
-
-
abstract fun advanceUntilIdle(): Long

Immediately execute all pending tasks and advance the virtual clock-time to the last delay.

If new tasks are scheduled due to advancing virtual time, they will be executed before advanceUntilIdle returns.

Return

the amount of delay-time that this Dispatcher's clock has been forwarded in milliseconds.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/cleanup-test-coroutines.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/cleanup-test-coroutines.html index 4012de00ac..02449d5a7c 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/cleanup-test-coroutines.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/cleanup-test-coroutines.html @@ -1,59 +1 @@ - - - - - cleanupTestCoroutines - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

cleanupTestCoroutines

-
-
-
-
abstract fun cleanupTestCoroutines()

Call after test code completes to ensure that the dispatcher is properly cleaned up.

Throws

if any pending tasks are active, however it will not throw for suspended coroutines.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/current-time.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/current-time.html index cbffd611de..03b4a55c57 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/current-time.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/current-time.html @@ -1,59 +1 @@ - - - - - currentTime - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

currentTime

-
-
-
-
abstract val currentTime: Long

Returns the current virtual clock-time as it is known to this Dispatcher.

Return

The virtual clock-time

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/index.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/index.html index 0c10ce3813..19fd9eb33c 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/index.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/index.html @@ -1,187 +1 @@ - - - - - DelayController - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

DelayController

-
-
-
interface DelayController

Control the virtual clock time of a CoroutineDispatcher.

Testing libraries may expose this interface to the tests instead of TestCoroutineDispatcher.

This interface is deprecated without replacement. Instead, TestCoroutineScheduler is supposed to be used to control the virtual time. Please see the migration guide for an instruction on how to update the code for the new API.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun advanceTimeBy(delayTimeMillis: Long): Long

Moves the Dispatcher's virtual clock forward by a specified amount of time.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun advanceUntilIdle(): Long

Immediately execute all pending tasks and advance the virtual clock-time to the last delay.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun cleanupTestCoroutines()

Call after test code completes to ensure that the dispatcher is properly cleaned up.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun pauseDispatcher()

Pause the dispatcher.

abstract suspend fun pauseDispatcher(block: suspend () -> Unit)

Run a block of code in a paused dispatcher.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun resumeDispatcher()

Resume the dispatcher from a paused state.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun runCurrent()

Run any tasks that are pending at or before the current virtual clock-time.

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val currentTime: Long

Returns the current virtual clock-time as it is known to this Dispatcher.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/pause-dispatcher.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/pause-dispatcher.html index 7bad314eee..ebf8e219b7 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/pause-dispatcher.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/pause-dispatcher.html @@ -1,59 +1 @@ - - - - - pauseDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

pauseDispatcher

-
-
-
-
abstract suspend fun pauseDispatcher(block: suspend () -> Unit)

Run a block of code in a paused dispatcher.

By pausing the dispatcher any new coroutines will not execute immediately. After block executes, the dispatcher will resume auto-advancing.

This is useful when testing functions that start a coroutine. By pausing the dispatcher assertions or setup may be done between the time the coroutine is created and started.


abstract fun pauseDispatcher()

Pause the dispatcher.

When paused, the dispatcher will not execute any coroutines automatically, and you must call runCurrent or advanceTimeBy, or advanceUntilIdle to execute coroutines.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/resume-dispatcher.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/resume-dispatcher.html index 002792b46c..a460095cfa 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/resume-dispatcher.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/resume-dispatcher.html @@ -1,59 +1 @@ - - - - - resumeDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

resumeDispatcher

-
-
-
-
abstract fun resumeDispatcher()

Resume the dispatcher from a paused state.

Resumed dispatchers will automatically progress through all coroutines scheduled at the current time. To advance time and execute coroutines scheduled in the future use, one of advanceTimeBy, or advanceUntilIdle.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/run-current.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/run-current.html index c4c097dffd..3444e429d4 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/run-current.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-delay-controller/run-current.html @@ -1,59 +1 @@ - - - - - runCurrent - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

runCurrent

-
-
-
-
abstract fun runCurrent()

Run any tasks that are pending at or before the current virtual clock-time.

Calling this function will never advance the clock.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-standard-test-dispatcher.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-standard-test-dispatcher.html index 282cebe105..4a7c18b38e 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-standard-test-dispatcher.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-standard-test-dispatcher.html @@ -1,59 +1 @@ - - - - - StandardTestDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

StandardTestDispatcher

-
-
-
-
fun StandardTestDispatcher(scheduler: TestCoroutineScheduler? = null, name: String? = null): TestDispatcher

Creates an instance of a TestDispatcher whose tasks are run inside calls to the scheduler.

This TestDispatcher instance does not itself execute any of the tasks. Instead, it always sends them to its scheduler, which can then be accessed via TestCoroutineScheduler.runCurrent, TestCoroutineScheduler.advanceUntilIdle, or TestCoroutineScheduler.advanceTimeBy, which will then execute these tasks in a blocking manner.

In practice, this means that launch or async blocks will not be entered immediately (unless they are parameterized with CoroutineStart.UNDISPATCHED), and one should either call TestCoroutineScheduler.runCurrent to run these pending tasks, which will block until there are no more tasks scheduled at this point in time, or, when inside runTest, call yield to yield the (only) thread used by runTest to the newly-launched coroutines.

If no scheduler is passed as an argument, Dispatchers.Main is checked, and if it was mocked with a TestDispatcher via Dispatchers.setMain, the TestDispatcher.scheduler of the mock dispatcher is used; if Dispatchers.Main is not mocked with a TestDispatcher, a new TestCoroutineScheduler is created.

One can additionally pass a name in order to more easily distinguish this dispatcher during debugging.

See also

for a dispatcher that is not confined to any particular thread.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-dispatcher/-test-coroutine-dispatcher.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-dispatcher/-test-coroutine-dispatcher.html index 1ba297d68e..55b59b9a5e 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-dispatcher/-test-coroutine-dispatcher.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-dispatcher/-test-coroutine-dispatcher.html @@ -1,59 +1 @@ - - - - - TestCoroutineDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

TestCoroutineDispatcher

-
-
-
-
fun TestCoroutineDispatcher(scheduler: TestCoroutineScheduler = TestCoroutineScheduler())
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-dispatcher/index.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-dispatcher/index.html index 05aaeb2904..84a5746209 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-dispatcher/index.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-dispatcher/index.html @@ -1,127 +1 @@ - - - - - TestCoroutineDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

TestCoroutineDispatcher

-
-
-
class TestCoroutineDispatcher(val scheduler: TestCoroutineScheduler = TestCoroutineScheduler()) : TestDispatcher, Delay, SchedulerAsDelayController

CoroutineDispatcher that performs both immediate and lazy execution of coroutines in tests and uses a TestCoroutineScheduler to control its virtual clock.

By default, TestCoroutineDispatcher is immediate. That means any tasks scheduled to be run without delay are immediately executed. If they were scheduled with a delay, the virtual clock-time must be advanced via one of the methods on the dispatcher's scheduler.

When switched to lazy execution using pauseDispatcher any coroutines started via launch or async will not execute until a call to DelayController.runCurrent or the virtual clock-time has been advanced via one of the methods on DelayController.

-
-
-
-
-

See also

- -

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun TestCoroutineDispatcher(scheduler: TestCoroutineScheduler = TestCoroutineScheduler())
-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
open override val scheduler: TestCoroutineScheduler

The scheduler that this dispatcher is linked to.

-
-
-
-
-
-

Extensions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun TestCoroutineDispatcher.runBlockingTest(block: suspend TestCoroutineScope.() -> Unit)

Convenience method for calling runBlockingTest on an existing TestCoroutineDispatcher.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-dispatcher/scheduler.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-dispatcher/scheduler.html index bbd0843917..e8ccf887e3 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-dispatcher/scheduler.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-dispatcher/scheduler.html @@ -1,59 +1 @@ - - - - - scheduler - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

scheduler

-
-
-
-
open override val scheduler: TestCoroutineScheduler

The scheduler that this dispatcher is linked to.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-exception-handler/-test-coroutine-exception-handler.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-exception-handler/-test-coroutine-exception-handler.html index c8bb4315a2..c4e681c5c9 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-exception-handler/-test-coroutine-exception-handler.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-exception-handler/-test-coroutine-exception-handler.html @@ -1,59 +1 @@ - - - - - TestCoroutineExceptionHandler - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

TestCoroutineExceptionHandler

-
-
-
-
fun TestCoroutineExceptionHandler()
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-exception-handler/cleanup-test-coroutines.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-exception-handler/cleanup-test-coroutines.html index 76bfc30f16..450714bf3c 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-exception-handler/cleanup-test-coroutines.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-exception-handler/cleanup-test-coroutines.html @@ -1,59 +1 @@ - - - - - cleanupTestCoroutines - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

cleanupTestCoroutines

-
-
-
-
open override fun cleanupTestCoroutines()

Call after the test completes to ensure that there were no uncaught exceptions.

The first exception in uncaughtExceptions is rethrown. All other exceptions are printed using Throwable.printStackTrace.

Throws

the first uncaught exception, if there are any uncaught exceptions.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-exception-handler/handle-exception.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-exception-handler/handle-exception.html index 45adc043a6..9843c7eb79 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-exception-handler/handle-exception.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-exception-handler/handle-exception.html @@ -1,59 +1 @@ - - - - - handleException - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

handleException

-
-
-
-
open override fun handleException(context: CoroutineContext, exception: Throwable)
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-exception-handler/index.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-exception-handler/index.html index db53fd89a1..ffa4fd2a1d 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-exception-handler/index.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-exception-handler/index.html @@ -1,138 +1 @@ - - - - - TestCoroutineExceptionHandler - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

TestCoroutineExceptionHandler

-
-
-

An exception handler that captures uncaught exceptions in tests.

-
-
-
-
-

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun TestCoroutineExceptionHandler()
-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
open override fun cleanupTestCoroutines()

Call after the test completes to ensure that there were no uncaught exceptions.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
open override fun handleException(context: CoroutineContext, exception: Throwable)
-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
open override val uncaughtExceptions: List<Throwable>

List of uncaught coroutine exceptions.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-exception-handler/uncaught-exceptions.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-exception-handler/uncaught-exceptions.html index 10001263b8..8efe8c335a 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-exception-handler/uncaught-exceptions.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-exception-handler/uncaught-exceptions.html @@ -1,59 +1 @@ - - - - - uncaughtExceptions - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

uncaughtExceptions

-
-
-
-
open override val uncaughtExceptions: List<Throwable>

List of uncaught coroutine exceptions.

The returned list is a copy of the currently caught exceptions. During cleanupTestCoroutines the first element of this list is rethrown if it is not empty.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/-test-coroutine-scheduler.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/-test-coroutine-scheduler.html index b3063ef9e4..31978a3356 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/-test-coroutine-scheduler.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/-test-coroutine-scheduler.html @@ -1,59 +1 @@ - - - - - TestCoroutineScheduler - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

TestCoroutineScheduler

-
-
-
-
fun TestCoroutineScheduler()
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/advance-time-by.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/advance-time-by.html index 58976502f1..35f222bef4 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/advance-time-by.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/advance-time-by.html @@ -1,59 +1 @@ - - - - - advanceTimeBy - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

advanceTimeBy

-
-
-
-
fun advanceTimeBy(delayTimeMillis: Long)

Moves the virtual clock of this dispatcher forward by the specified amount, running the scheduled tasks in the meantime.

Breaking changes from TestCoroutineDispatcher.advanceTimeBy:

  • Intentionally doesn't return a Long value, as its use cases are unclear. We may restore it in the future; please describe your use cases at the issue tracker. For now, it's possible to query currentTime before and after execution of this method, to the same effect.

  • It doesn't run the tasks that are scheduled at exactly currentTime + delayTimeMillis. For example, advancing the time by one millisecond used to run the tasks at the current millisecond and the next millisecond, but now will stop just before executing any task starting at the next millisecond.

  • Overflowing the target time used to lead to nothing being done, but will now run the tasks scheduled at up to (but not including) Long.MAX_VALUE.

Throws

if passed a negative delay.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/advance-until-idle.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/advance-until-idle.html index c79aa2f88e..fcb21d7b25 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/advance-until-idle.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/advance-until-idle.html @@ -1,59 +1 @@ - - - - - advanceUntilIdle - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

advanceUntilIdle

-
-
-
-
fun advanceUntilIdle()

Runs the enqueued tasks in the specified order, advancing the virtual time as needed until there are no more tasks associated with the dispatchers linked to this scheduler.

A breaking change from TestCoroutineDispatcher.advanceTimeBy is that it no longer returns the total number of milliseconds by which the execution of this method has advanced the virtual time. If you want to recreate that functionality, query currentTime before and after the execution to achieve the same result.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/current-time.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/current-time.html index f651b6ebfc..3b77f86bfc 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/current-time.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/current-time.html @@ -1,59 +1 @@ - - - - - currentTime - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

currentTime

-
-
-
-
val currentTime: Long = 0

The current virtual time in milliseconds.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/index.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/index.html index d792de2472..37a90c631e 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/index.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/index.html @@ -1,172 +1 @@ - - - - - TestCoroutineScheduler - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

TestCoroutineScheduler

-
-
-

This is a scheduler for coroutines used in tests, providing the delay-skipping behavior.

Test dispatchers are parameterized with a scheduler. Several dispatchers can share the same scheduler, in which case their knowledge about the virtual time will be synchronized. When the dispatchers require scheduling an event at a later point in time, they notify the scheduler, which will establish the order of the tasks.

The scheduler can be queried to advance the time (via advanceTimeBy), run all the scheduled tasks advancing the virtual time as needed (via advanceUntilIdle), or run the tasks that are scheduled to run as soon as possible but haven't yet been dispatched (via runCurrent).

-
-
-
-
-

Constructors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun TestCoroutineScheduler()
-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun advanceTimeBy(delayTimeMillis: Long)

Moves the virtual clock of this dispatcher forward by the specified amount, running the scheduled tasks in the meantime.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun advanceUntilIdle()

Runs the enqueued tasks in the specified order, advancing the virtual time as needed until there are no more tasks associated with the dispatchers linked to this scheduler.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun runCurrent()

Runs the tasks that are scheduled to execute at this moment of virtual time.

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
val currentTime: Long = 0

The current virtual time in milliseconds.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Returns the TimeSource representation of the virtual time of this scheduler.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/run-current.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/run-current.html index 89314179da..e8d5c839aa 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/run-current.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/run-current.html @@ -1,59 +1 @@ - - - - - runCurrent - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

runCurrent

-
-
-
-
fun runCurrent()

Runs the tasks that are scheduled to execute at this moment of virtual time.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/time-source.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/time-source.html index 3f438fc56e..448c40f6cf 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/time-source.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scheduler/time-source.html @@ -1,59 +1 @@ - - - - - timeSource - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

timeSource

-
-
-
-

Returns the TimeSource representation of the virtual time of this scheduler.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scope.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scope.html index 3894130b4d..c531060a82 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scope.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scope.html @@ -1,59 +1 @@ - - - - - TestCoroutineScope - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

TestCoroutineScope

-
-
-
-
fun TestCoroutineScope(context: CoroutineContext = EmptyCoroutineContext): TestCoroutineScope

A coroutine scope for launching test coroutines using TestCoroutineDispatcher.

createTestCoroutineScope is a similar function that defaults to StandardTestDispatcher.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scope/cleanup-test-coroutines.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scope/cleanup-test-coroutines.html index 9c6c0a9ff8..1d6e6b1be8 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scope/cleanup-test-coroutines.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scope/cleanup-test-coroutines.html @@ -1,59 +1 @@ - - - - - cleanupTestCoroutines - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

cleanupTestCoroutines

-
-
-
-
abstract fun cleanupTestCoroutines()

Called after the test completes.

For backward compatibility, if the CoroutineExceptionHandler is an UncaughtExceptionCaptor, its TestCoroutineExceptionHandler.cleanupTestCoroutines behavior is performed. Likewise, if the ContinuationInterceptor is a DelayController, its DelayController.cleanupTestCoroutines is called.

Throws

the first uncaught exception, if there are any uncaught exceptions.

if any pending tasks are active.

if called more than once.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scope/index.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scope/index.html index 13e3d57552..a765b1225b 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scope/index.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scope/index.html @@ -1,257 +1 @@ - - - - - TestCoroutineScope - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

TestCoroutineScope

-
-
-
interface TestCoroutineScope : CoroutineScope

A scope which provides detailed control over the execution of coroutines for tests.

This scope is deprecated in favor of TestScope. Please see the migration guide for an instruction on how to update the code for the new API.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun cleanupTestCoroutines()

Called after the test completes.

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val testScheduler: TestCoroutineScheduler

The delay-skipping scheduler used by the test dispatchers running the code in this scope.

-
-
-
-
-
-

Extensions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun TestCoroutineScope.advanceTimeBy(delayTimeMillis: Long)

Advances the testScheduler by delayTimeMillis and runs the tasks up to that moment (inclusive).

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Advances the testScheduler to the point where there are no tasks remaining.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

The current virtual time on testScheduler.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun TestCoroutineScope.pauseDispatcher(block: suspend () -> Unit)
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun TestCoroutineScope.runBlockingTest(block: suspend TestCoroutineScope.() -> Unit)

Convenience method for calling runBlockingTest on an existing TestCoroutineScope.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

Run any tasks that are pending at the current virtual time, according to the testScheduler.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun TestCoroutineScope.runTest(dispatchTimeoutMs: Long = DEFAULT_DISPATCH_TIMEOUT_MS, block: suspend TestCoroutineScope.() -> Unit): TestResult

Runs a test in a TestCoroutineScope based on this one.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
val TestCoroutineScope.uncaughtExceptions: List<Throwable>

List of uncaught coroutine exceptions, for backward compatibility.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scope/test-scheduler.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scope/test-scheduler.html index 1cf40effa3..0ad5485cf1 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scope/test-scheduler.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-scope/test-scheduler.html @@ -1,59 +1 @@ - - - - - testScheduler - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

testScheduler

-
-
-
-
abstract val testScheduler: TestCoroutineScheduler

The delay-skipping scheduler used by the test dispatchers running the code in this scope.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-dispatcher/index.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-dispatcher/index.html index f283d62480..c6e5347249 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-dispatcher/index.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-dispatcher/index.html @@ -1,97 +1 @@ - - - - - TestDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

TestDispatcher

-
-
-
abstract class TestDispatcher : CoroutineDispatcher, Delay

A test dispatcher that can interface with a TestCoroutineScheduler.

The available implementations are:

-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val scheduler: TestCoroutineScheduler

The scheduler that this dispatcher is linked to.

-
-
-
-
-
-

Inheritors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-dispatcher/scheduler.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-dispatcher/scheduler.html index 42fad3b49c..403e93d1d3 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-dispatcher/scheduler.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-dispatcher/scheduler.html @@ -1,59 +1 @@ - - - - - scheduler - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

scheduler

-
-
-
-
abstract val scheduler: TestCoroutineScheduler

The scheduler that this dispatcher is linked to.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-result/index.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-result/index.html index 9d11428148..4e2538c5c0 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-result/index.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-result/index.html @@ -1,66 +1 @@ - - - - - TestResult - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

TestResult

-
-
-
expect class TestResult

A test result.

  • On JVM and Native, this resolves to Unit, representing the fact that tests are run in a blocking manner on these platforms: a call to a function returning a TestResult will simply execute the test inside it.

  • On JS, this is a Promise, which reflects the fact that the test-running function does not wait for a test to finish. The JS test frameworks typically support returning Promise from a test and will correctly handle it.

Because of the behavior on JS, extra care must be taken when writing multiplatform tests to avoid losing test errors:

  • Don't do anything after running the functions returning a TestResult. On JS, this code will execute before the test finishes.

  • As a corollary, don't run functions returning a TestResult more than once per test. The only valid thing to do with a TestResult is to immediately return it from a test.

  • Don't nest functions returning a TestResult.

actual typealias TestResult = Promise<Unit>
actual typealias TestResult = Unit
actual typealias TestResult = Unit
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-scope.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-scope.html index b3ced89f16..3d945c62f9 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-scope.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-scope.html @@ -1,59 +1 @@ - - - - - TestScope - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

TestScope

-
-
-
-
fun TestScope(context: CoroutineContext = EmptyCoroutineContext): TestScope

Creates a TestScope.

It ensures that all the test module machinery is properly initialized.

  • If context doesn't provide a TestCoroutineScheduler for orchestrating the virtual time used for delay-skipping, a new one is created, unless either

  • If context doesn't have a TestDispatcher, a StandardTestDispatcher is created.

  • A CoroutineExceptionHandler is created that makes TestCoroutineScope.cleanupTestCoroutines throw if there were any uncaught exceptions, or forwards the exceptions further in a platform-specific manner if the cleanup was already performed when an exception happened. Passing a CoroutineExceptionHandler is illegal, unless it's an UncaughtExceptionCaptor, in which case the behavior is preserved for the time being for backward compatibility. If you need to have a specific CoroutineExceptionHandler, please pass it to launch on an already-created TestCoroutineScope and share your use case at our issue tracker.

  • If context provides a Job, that job is used as a parent for the new scope.

Throws

if context has an CoroutineExceptionHandler that is not an UncaughtExceptionCaptor.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-scope/index.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-scope/index.html index d1e578f972..49da0c598d 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-scope/index.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-scope/index.html @@ -1,205 +1 @@ - - - - - TestScope - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

TestScope

-
-
-
interface TestScope : CoroutineScope

A coroutine scope that for launching test coroutines.

The scope provides the following functionality:

The usual way to access a TestScope is to call runTest, but it can also be constructed manually, in order to use it to initialize the components that participate in the test.

Differences from the deprecated TestCoroutineScope

  • This doesn't provide an equivalent of TestCoroutineScope.cleanupTestCoroutines, and so can't be used as a standalone mechanism for writing tests: it does require that runTest is eventually called. The reason for this is that a proper cleanup procedure that supports using non-test dispatchers and arbitrary coroutine suspensions would be equivalent to runTest, but would also be more error-prone, due to the potential for forgetting to perform the cleanup.

  • TestCoroutineScope.advanceTimeBy also calls TestCoroutineScheduler.runCurrent after advancing the virtual time.

  • No support for dispatcher pausing, like DelayController allows. TestCoroutineDispatcher, which supported pausing, is deprecated; now, instead of pausing a dispatcher, one can use withContext to run a dispatcher that's paused by default, like StandardTestDispatcher.

  • No access to the list of unhandled exceptions.

-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val testScheduler: TestCoroutineScheduler

The delay-skipping scheduler used by the test dispatchers running the code in this scope.

-
-
-
-
-
-

Extensions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun TestScope.advanceTimeBy(delayTimeMillis: Long)

Moves the virtual clock of this dispatcher forward by the specified amount, running the scheduled tasks in the meantime.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun TestScope.advanceUntilIdle()

Advances the testScheduler to the point where there are no tasks remaining.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
val TestScope.currentTime: Long

The current virtual time on testScheduler.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun TestScope.runBlockingTest(block: suspend TestScope.() -> Unit)

Convenience method for calling runBlockingTestOnTestScope on an existing TestScope.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun TestScope.runCurrent()

Run any tasks that are pending at the current virtual time, according to the testScheduler.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun TestScope.runTest(dispatchTimeoutMs: Long = DEFAULT_DISPATCH_TIMEOUT_MS, testBody: suspend TestScope.() -> Unit): TestResult

Performs runTest on an existing TestScope.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
- -
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-scope/test-scheduler.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-scope/test-scheduler.html index f46e979eec..728191f32c 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-scope/test-scheduler.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-scope/test-scheduler.html @@ -1,59 +1 @@ - - - - - testScheduler - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

testScheduler

-
-
-
-
abstract val testScheduler: TestCoroutineScheduler

The delay-skipping scheduler used by the test dispatchers running the code in this scope.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-uncaught-exception-captor/cleanup-test-coroutines.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-uncaught-exception-captor/cleanup-test-coroutines.html index dd58cff170..8a6fed0d09 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-uncaught-exception-captor/cleanup-test-coroutines.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-uncaught-exception-captor/cleanup-test-coroutines.html @@ -1,59 +1 @@ - - - - - cleanupTestCoroutines - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

cleanupTestCoroutines

-
-
-
-
abstract fun cleanupTestCoroutines()

Call after the test completes to ensure that there were no uncaught exceptions.

The first exception in uncaughtExceptions is rethrown. All other exceptions are printed using Throwable.printStackTrace.

Throws

the first uncaught exception, if there are any uncaught exceptions.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-uncaught-exception-captor/index.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-uncaught-exception-captor/index.html index d62b83ade0..3cc4df1a5f 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-uncaught-exception-captor/index.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-uncaught-exception-captor/index.html @@ -1,115 +1 @@ - - - - - UncaughtExceptionCaptor - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

UncaughtExceptionCaptor

-
-
-
interface UncaughtExceptionCaptor

Access uncaught coroutine exceptions captured during test execution.

-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract fun cleanupTestCoroutines()

Call after the test completes to ensure that there were no uncaught exceptions.

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract val uncaughtExceptions: List<Throwable>

List of uncaught coroutine exceptions.

-
-
-
-
-
-

Inheritors

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-uncaught-exception-captor/uncaught-exceptions.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-uncaught-exception-captor/uncaught-exceptions.html index 64fa39e4d5..8d514e7e90 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-uncaught-exception-captor/uncaught-exceptions.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-uncaught-exception-captor/uncaught-exceptions.html @@ -1,59 +1 @@ - - - - - uncaughtExceptions - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

uncaughtExceptions

-
-
-
-
abstract val uncaughtExceptions: List<Throwable>

List of uncaught coroutine exceptions.

The returned list is a copy of the currently caught exceptions. During cleanupTestCoroutines the first element of this list is rethrown if it is not empty.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/-unconfined-test-dispatcher.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/-unconfined-test-dispatcher.html index af2f9c1338..1f444bca1a 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/-unconfined-test-dispatcher.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/-unconfined-test-dispatcher.html @@ -1,59 +1 @@ - - - - - UnconfinedTestDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

UnconfinedTestDispatcher

-
-
-
-
fun UnconfinedTestDispatcher(scheduler: TestCoroutineScheduler? = null, name: String? = null): TestDispatcher

Creates an instance of an unconfined TestDispatcher.

This dispatcher is similar to Dispatchers.Unconfined: the tasks that it executes are not confined to any particular thread and form an event loop; it's different in that it skips delays, as all TestDispatchers do.

Like Dispatchers.Unconfined, this one does not provide guarantees about the execution order when several coroutines are queued in this dispatcher. However, we ensure that the launch and async blocks at the top level of runTest are entered eagerly. This allows launching child coroutines and not calling runCurrent for them to start executing.

@Test
fun testEagerlyEnteringChildCoroutines() = runTest(UnconfinedTestDispatcher()) {
var entered = false
val deferred = CompletableDeferred<Unit>()
var completed = false
launch {
entered = true
deferred.await()
completed = true
}
assertTrue(entered) // `entered = true` already executed.
assertFalse(completed) // however, the child coroutine then suspended, so it is enqueued.
deferred.complete(Unit) // resume the coroutine.
assertTrue(completed) // now the child coroutine is immediately completed.
}

Using this TestDispatcher can greatly simplify writing tests where it's not important which thread is used when and in which order the queued coroutines are executed. Another typical use case for this dispatcher is launching child coroutines that are resumed immediately, without going through a dispatch; this can be helpful for testing Channel and StateFlow usages.

@Test
fun testUnconfinedDispatcher() = runTest {
val values = mutableListOf<Int>()
val stateFlow = MutableStateFlow(0)
val job = launch(UnconfinedTestDispatcher(testScheduler)) {
stateFlow.collect {
values.add(it)
}
}
stateFlow.value = 1
stateFlow.value = 2
stateFlow.value = 3
job.cancel()
// each assignment will immediately resume the collecting child coroutine,
// so no values will be skipped.
assertEquals(listOf(0, 1, 2, 3), values)
}

Please be aware that, like Dispatchers.Unconfined, this is a specific dispatcher with execution order guarantees that are unusual and not shared by most other dispatchers, so it can only be used reliably for testing functionality, not the specific order of actions. See Dispatchers.Unconfined for a discussion of the execution order guarantees.

In order to support delay skipping, this dispatcher is linked to a TestCoroutineScheduler, which is used to control the virtual time and can be shared among many test dispatchers. If no scheduler is passed as an argument, Dispatchers.Main is checked, and if it was mocked with a TestDispatcher via Dispatchers.setMain, the TestDispatcher.scheduler of the mock dispatcher is used; if Dispatchers.Main is not mocked with a TestDispatcher, a new TestCoroutineScheduler is created.

Additionally, name can be set to distinguish each dispatcher instance when debugging.

See also

for a more predictable TestDispatcher.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/advance-time-by.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/advance-time-by.html index c4b2766460..b748748232 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/advance-time-by.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/advance-time-by.html @@ -1,60 +1 @@ - - - - - advanceTimeBy - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

advanceTimeBy

-
-
-
-
fun TestScope.advanceTimeBy(delayTimeMillis: Long)

Moves the virtual clock of this dispatcher forward by the specified amount, running the scheduled tasks in the meantime.

In contrast with TestCoroutineScope.advanceTimeBy, this function does not run the tasks scheduled at the moment currentTime + delayTimeMillis.

See also

Throws

if passed a negative delay.

fun TestCoroutineScope.advanceTimeBy(delayTimeMillis: Long)

Advances the testScheduler by delayTimeMillis and runs the tasks up to that moment (inclusive).

See also

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/advance-until-idle.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/advance-until-idle.html index 63d6b64e0c..91bf33a34d 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/advance-until-idle.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/advance-until-idle.html @@ -1,60 +1 @@ - - - - - advanceUntilIdle - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

advanceUntilIdle

-
-
-
-
fun TestScope.advanceUntilIdle()

Advances the testScheduler to the point where there are no tasks remaining.

See also

Advances the testScheduler to the point where there are no tasks remaining.

See also

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/create-test-coroutine-scope.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/create-test-coroutine-scope.html index 152079475b..48b89978a1 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/create-test-coroutine-scope.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/create-test-coroutine-scope.html @@ -1,59 +1 @@ - - - - - createTestCoroutineScope - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

createTestCoroutineScope

-
-
-
-
fun createTestCoroutineScope(context: CoroutineContext = EmptyCoroutineContext): TestCoroutineScope

A coroutine scope for launching test coroutines.

This is a function for aiding in migration from TestCoroutineScope to TestScope. Please see the migration guide for an instruction on how to update the code for the new API.

It ensures that all the test module machinery is properly initialized.

  • If context doesn't define a TestCoroutineScheduler for orchestrating the virtual time used for delay-skipping, a new one is created, unless either

Throws

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/current-time.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/current-time.html index 02553c4a7c..428a9c5523 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/current-time.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/current-time.html @@ -1,60 +1 @@ - - - - - currentTime - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

currentTime

-
-
-
-
val TestScope.currentTime: Long

The current virtual time on testScheduler.

See also

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/index.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/index.html index 7a48d7e17a..5157efe398 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/index.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/index.html @@ -1,546 +1 @@ - - - - - kotlinx.coroutines.test - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

Package kotlinx.coroutines.test

-
-
-
-
-

Types

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface DelayController

Control the virtual clock time of a CoroutineDispatcher.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
class TestCoroutineDispatcher(val scheduler: TestCoroutineScheduler = TestCoroutineScheduler()) : TestDispatcher, Delay, SchedulerAsDelayController

CoroutineDispatcher that performs both immediate and lazy execution of coroutines in tests and uses a TestCoroutineScheduler to control its virtual clock.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

An exception handler that captures uncaught exceptions in tests.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-

This is a scheduler for coroutines used in tests, providing the delay-skipping behavior.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface TestCoroutineScope : CoroutineScope

A scope which provides detailed control over the execution of coroutines for tests.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
abstract class TestDispatcher : CoroutineDispatcher, Delay

A test dispatcher that can interface with a TestCoroutineScheduler.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
expect class TestResult

A test result.

actual typealias TestResult = Promise<Unit>
actual typealias TestResult = Unit
actual typealias TestResult = Unit
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface TestScope : CoroutineScope

A coroutine scope that for launching test coroutines.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
interface UncaughtExceptionCaptor

Access uncaught coroutine exceptions captured during test execution.

-
-
-
-
-
-

Functions

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun TestScope.advanceTimeBy(delayTimeMillis: Long)

Moves the virtual clock of this dispatcher forward by the specified amount, running the scheduled tasks in the meantime.

fun TestCoroutineScope.advanceTimeBy(delayTimeMillis: Long)

Advances the testScheduler by delayTimeMillis and runs the tasks up to that moment (inclusive).

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun TestScope.advanceUntilIdle()

Advances the testScheduler to the point where there are no tasks remaining.

Advances the testScheduler to the point where there are no tasks remaining.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun createTestCoroutineScope(context: CoroutineContext = EmptyCoroutineContext): TestCoroutineScope

A coroutine scope for launching test coroutines.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
suspend fun TestCoroutineScope.pauseDispatcher(block: suspend () -> Unit)
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun Dispatchers.resetMain()

Resets state of the Dispatchers.Main to the original main dispatcher.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun TestCoroutineDispatcher.runBlockingTest(block: suspend TestCoroutineScope.() -> Unit)

Convenience method for calling runBlockingTest on an existing TestCoroutineDispatcher.

fun TestCoroutineScope.runBlockingTest(block: suspend TestCoroutineScope.() -> Unit)

Convenience method for calling runBlockingTest on an existing TestCoroutineScope.

fun TestScope.runBlockingTest(block: suspend TestScope.() -> Unit)

Convenience method for calling runBlockingTestOnTestScope on an existing TestScope.

fun runBlockingTest(context: CoroutineContext = EmptyCoroutineContext, testBody: suspend TestCoroutineScope.() -> Unit)

Executes a testBody inside an immediate execution dispatcher.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun runBlockingTestOnTestScope(context: CoroutineContext = EmptyCoroutineContext, testBody: suspend TestScope.() -> Unit)

A version of runBlockingTest that works with TestScope.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun TestScope.runCurrent()

Run any tasks that are pending at the current virtual time, according to the testScheduler.

Run any tasks that are pending at the current virtual time, according to the testScheduler.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun TestScope.runTest(dispatchTimeoutMs: Long = DEFAULT_DISPATCH_TIMEOUT_MS, testBody: suspend TestScope.() -> Unit): TestResult

Performs runTest on an existing TestScope.

fun runTest(    context: CoroutineContext = EmptyCoroutineContext,     dispatchTimeoutMs: Long = DEFAULT_DISPATCH_TIMEOUT_MS,     testBody: suspend TestScope.() -> Unit): TestResult

Executes testBody as a test in a new coroutine, returning TestResult.

fun TestCoroutineScope.runTest(dispatchTimeoutMs: Long = DEFAULT_DISPATCH_TIMEOUT_MS, block: suspend TestCoroutineScope.() -> Unit): TestResult

Runs a test in a TestCoroutineScope based on this one.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun runTestWithLegacyScope(    context: CoroutineContext = EmptyCoroutineContext,     dispatchTimeoutMs: Long = DEFAULT_DISPATCH_TIMEOUT_MS,     testBody: suspend TestCoroutineScope.() -> Unit): TestResult

This is an overload of runTest that works with TestCoroutineScope.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun Dispatchers.setMain(dispatcher: CoroutineDispatcher)

Sets the given dispatcher as an underlying dispatcher of Dispatchers.Main. All subsequent usages of Dispatchers.Main will use the given dispatcher under the hood.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun StandardTestDispatcher(scheduler: TestCoroutineScheduler? = null, name: String? = null): TestDispatcher

Creates an instance of a TestDispatcher whose tasks are run inside calls to the scheduler.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun TestCoroutineScope(context: CoroutineContext = EmptyCoroutineContext): TestCoroutineScope

A coroutine scope for launching test coroutines using TestCoroutineDispatcher.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun TestScope(context: CoroutineContext = EmptyCoroutineContext): TestScope

Creates a TestScope.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
fun UnconfinedTestDispatcher(scheduler: TestCoroutineScheduler? = null, name: String? = null): TestDispatcher

Creates an instance of an unconfined TestDispatcher.

-
-
-
-
-
-

Properties

-
-
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
val TestScope.currentTime: Long

The current virtual time on testScheduler.

The current virtual time on testScheduler.

-
-
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
- -
-
-
- -
-
-
- - -
Link copied to clipboard
-
-
-
-
-
-
val TestCoroutineScope.uncaughtExceptions: List<Throwable>

List of uncaught coroutine exceptions, for backward compatibility.

-
-
-
-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/pause-dispatcher.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/pause-dispatcher.html index ae91bac157..4fc549dcbd 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/pause-dispatcher.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/pause-dispatcher.html @@ -1,59 +1 @@ - - - - - pauseDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

pauseDispatcher

-
-
-
-
suspend fun TestCoroutineScope.pauseDispatcher(block: suspend () -> Unit)
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/reset-main.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/reset-main.html index bbe2e748de..e2388370a6 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/reset-main.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/reset-main.html @@ -1,59 +1 @@ - - - - - resetMain - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

resetMain

-
-
-
-
fun Dispatchers.resetMain()

Resets state of the Dispatchers.Main to the original main dispatcher.

For example, in Android, the Main thread dispatcher will be set as Dispatchers.Main. This method undoes a dependency injection performed for tests, and so should be used in tear down (@After) methods.

It is unsafe to call this method if alive coroutines launched in Dispatchers.Main exist.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/resume-dispatcher.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/resume-dispatcher.html index 83f50f7379..8e0fdab4db 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/resume-dispatcher.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/resume-dispatcher.html @@ -1,59 +1 @@ - - - - - resumeDispatcher - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

resumeDispatcher

-
-
-
-
-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/run-blocking-test-on-test-scope.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/run-blocking-test-on-test-scope.html index 1353634579..ca78121934 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/run-blocking-test-on-test-scope.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/run-blocking-test-on-test-scope.html @@ -1,59 +1 @@ - - - - - runBlockingTestOnTestScope - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

runBlockingTestOnTestScope

-
-
-
-
fun runBlockingTestOnTestScope(context: CoroutineContext = EmptyCoroutineContext, testBody: suspend TestScope.() -> Unit)

A version of runBlockingTest that works with TestScope.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/run-blocking-test.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/run-blocking-test.html index 2faaf1a20a..ccb20db752 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/run-blocking-test.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/run-blocking-test.html @@ -1,59 +1 @@ - - - - - runBlockingTest - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

runBlockingTest

-
-
-
-
fun runBlockingTest(context: CoroutineContext = EmptyCoroutineContext, testBody: suspend TestCoroutineScope.() -> Unit)

Executes a testBody inside an immediate execution dispatcher.

This method is deprecated in favor of runTest. Please see the migration guide for an instruction on how to update the code for the new API.

This is similar to runBlocking but it will immediately progress past delays and into launch and async blocks. You can use this to write tests that execute in the presence of calls to delay without causing your test to take extra time.

@Test
fun exampleTest() = runBlockingTest {
val deferred = async {
delay(1_000)
async {
delay(1_000)
}.await()
}

deferred.await() // result available immediately
}

This method requires that all coroutines launched inside testBody complete, or are cancelled, as part of the test conditions.

Unhandled exceptions thrown by coroutines in the test will be re-thrown at the end of the test.

Parameters

context

additional context elements. If context contains CoroutineDispatcher or CoroutineExceptionHandler, then they must implement DelayController and TestCoroutineExceptionHandler respectively.

testBody

The code of the unit-test.

Throws

If the testBody does not complete (or cancel) all coroutines that it launches (including coroutines suspended on join/await).


fun TestCoroutineScope.runBlockingTest(block: suspend TestCoroutineScope.() -> Unit)

Convenience method for calling runBlockingTest on an existing TestCoroutineScope.

This method is deprecated in favor of runTest, whereas TestCoroutineScope is deprecated in favor of TestScope. Please see the migration guide for an instruction on how to update the code for the new API.


fun TestScope.runBlockingTest(block: suspend TestScope.() -> Unit)

Convenience method for calling runBlockingTestOnTestScope on an existing TestScope.


fun TestCoroutineDispatcher.runBlockingTest(block: suspend TestCoroutineScope.() -> Unit)

Convenience method for calling runBlockingTest on an existing TestCoroutineDispatcher.

This method is deprecated in favor of runTest, whereas TestCoroutineScope is deprecated in favor of TestScope. Please see the migration guide for an instruction on how to update the code for the new API.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/run-current.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/run-current.html index 7cbcfa66af..4ac47ecd8a 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/run-current.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/run-current.html @@ -1,60 +1 @@ - - - - - runCurrent - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

runCurrent

-
-
-
-
fun TestScope.runCurrent()

Run any tasks that are pending at the current virtual time, according to the testScheduler.

See also

Run any tasks that are pending at the current virtual time, according to the testScheduler.

See also

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/run-test-with-legacy-scope.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/run-test-with-legacy-scope.html index 0bfbac0ab6..2c235a7572 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/run-test-with-legacy-scope.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/run-test-with-legacy-scope.html @@ -1,59 +1 @@ - - - - - runTestWithLegacyScope - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

runTestWithLegacyScope

-
-
-
-
fun runTestWithLegacyScope(    context: CoroutineContext = EmptyCoroutineContext,     dispatchTimeoutMs: Long = DEFAULT_DISPATCH_TIMEOUT_MS,     testBody: suspend TestCoroutineScope.() -> Unit): TestResult

This is an overload of runTest that works with TestCoroutineScope.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/run-test.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/run-test.html index 8fcd277339..2afcf10e63 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/run-test.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/run-test.html @@ -1,60 +1 @@ - - - - - runTest - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

runTest

-
-
-
-
fun runTest(    context: CoroutineContext = EmptyCoroutineContext,     dispatchTimeoutMs: Long = DEFAULT_DISPATCH_TIMEOUT_MS,     testBody: suspend TestScope.() -> Unit): TestResult

Executes testBody as a test in a new coroutine, returning TestResult.

On JVM and Native, this function behaves similarly to runBlocking, with the difference that the code that it runs will skip delays. This allows to use delay in without causing the tests to take more time than necessary. On JS, this function creates a Promise that executes the test body with the delay-skipping behavior.

@Test
fun exampleTest() = runTest {
val deferred = async {
delay(1_000)
async {
delay(1_000)
}.await()
}

deferred.await() // result available immediately
}

The platform difference entails that, in order to use this function correctly in common code, one must always immediately return the produced TestResult from the test method, without doing anything else afterwards. See TestResult for details on this.

The test is run in a single thread, unless other CoroutineDispatcher are used for child coroutines. Because of this, child coroutines are not executed in parallel to the test body. In order to for the spawned-off asynchronous code to actually be executed, one must either yield or suspend the test body some other way, or use commands that control scheduling (see TestCoroutineScheduler).

@Test
fun exampleWaitingForAsyncTasks1() = runTest {
// 1
val job = launch {
// 3
}
// 2
job.join() // the main test coroutine suspends here, so the child is executed
// 4
}

@Test
fun exampleWaitingForAsyncTasks2() = runTest {
// 1
launch {
// 3
}
// 2
advanceUntilIdle() // runs the tasks until their queue is empty
// 4
}

Task scheduling

Delay-skipping is achieved by using virtual time. If Dispatchers.Main is set to a TestDispatcher via Dispatchers.setMain before the test, then its TestCoroutineScheduler is used; otherwise, a new one is automatically created (or taken from context in some way) and can be used to control the virtual time, advancing it, running the tasks scheduled at a specific time etc. Some convenience methods are available on TestScope to control the scheduler.

Delays in code that runs inside dispatchers that don't use a TestCoroutineScheduler don't get skipped:

@Test
fun exampleTest() = runTest {
val elapsed = TimeSource.Monotonic.measureTime {
val deferred = async {
delay(1_000) // will be skipped
withContext(Dispatchers.Default) {
delay(5_000) // Dispatchers.Default doesn't know about TestCoroutineScheduler
}
}
deferred.await()
}
println(elapsed) // about five seconds
}

Failures

Test body failures

If the created coroutine completes with an exception, then this exception will be thrown at the end of the test.

Reported exceptions

Unhandled exceptions will be thrown at the end of the test. If the uncaught exceptions happen after the test finishes, the error is propagated in a platform-specific manner. If the test coroutine completes with an exception, the unhandled exceptions are suppressed by it.

Uncompleted coroutines

This method requires that, after the test coroutine has completed, all the other coroutines launched inside testBody also complete, or are cancelled. Otherwise, the test will be failed (which, on JVM and Native, means that runTest itself will throw AssertionError, whereas on JS, the Promise will fail with it).

In the general case, if there are active jobs, it's impossible to detect if they are going to complete eventually due to the asynchronous nature of coroutines. In order to prevent tests hanging in this scenario, runTest will wait for dispatchTimeoutMs milliseconds (by default, 60 seconds) from the moment when TestCoroutineScheduler becomes idle before throwing AssertionError. If some dispatcher linked to TestCoroutineScheduler receives a task during that time, the timer gets reset.

Configuration

context can be used to affect the environment of the code under test. Beside just being passed to the coroutine scope created for the test, context also can be used to change how the test is executed. See the TestScope constructor function documentation for details.

Throws

if the context is invalid. See the TestScope constructor docs for details.


fun TestScope.runTest(dispatchTimeoutMs: Long = DEFAULT_DISPATCH_TIMEOUT_MS, testBody: suspend TestScope.() -> Unit): TestResult

Performs runTest on an existing TestScope.

fun TestCoroutineScope.runTest(dispatchTimeoutMs: Long = DEFAULT_DISPATCH_TIMEOUT_MS, block: suspend TestCoroutineScope.() -> Unit): TestResult

Runs a test in a TestCoroutineScope based on this one.

Calls runTest using a coroutine context from this TestCoroutineScope. The TestCoroutineScope used to run the block will be different from this one, but will use its Job as a parent.

Since this function returns TestResult, in order to work correctly on the JS, its result must be returned immediately from the test body. See the docs for TestResult for details.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/set-main.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/set-main.html index d58587ee79..5129534557 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/set-main.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/set-main.html @@ -1,59 +1 @@ - - - - - setMain - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

setMain

-
-
-
-
fun Dispatchers.setMain(dispatcher: CoroutineDispatcher)

Sets the given dispatcher as an underlying dispatcher of Dispatchers.Main. All subsequent usages of Dispatchers.Main will use the given dispatcher under the hood.

Using TestDispatcher as an argument has special behavior: subsequently-called runTest, as well as TestScope and test dispatcher constructors, will use the TestCoroutineScheduler of the provided dispatcher.

It is unsafe to call this method if alive coroutines launched in Dispatchers.Main exist.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/test-time-source.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/test-time-source.html index 9cf18beedc..80cea76af4 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/test-time-source.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/test-time-source.html @@ -1,59 +1 @@ - - - - - testTimeSource - - - - - - - - - - - - - - - -
-
-
-
- -
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/kotlinx.coroutines.test/uncaught-exceptions.html b/kotlinx-coroutines-test/kotlinx.coroutines.test/uncaught-exceptions.html index 3305b72396..fca81a9adb 100644 --- a/kotlinx-coroutines-test/kotlinx.coroutines.test/uncaught-exceptions.html +++ b/kotlinx-coroutines-test/kotlinx.coroutines.test/uncaught-exceptions.html @@ -1,59 +1 @@ - - - - - uncaughtExceptions - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-

uncaughtExceptions

-
-
-
-
val TestCoroutineScope.uncaughtExceptions: List<Throwable>

List of uncaught coroutine exceptions, for backward compatibility.

The returned list is a copy of the exceptions caught during execution. During TestCoroutineScope.cleanupTestCoroutines the first element of this list is rethrown if it is not empty.

Exceptions are only collected in this list if the UncaughtExceptionCaptor is in the test context.

-
- -
-
- - - + \ No newline at end of file diff --git a/kotlinx-coroutines-test/navigation.html b/kotlinx-coroutines-test/navigation.html deleted file mode 100644 index be03fe14df..0000000000 --- a/kotlinx-coroutines-test/navigation.html +++ /dev/null @@ -1,2047 +0,0 @@ -
- -
- -
- - - -
- -
-
- -
-
- -
-
-
- async() -
-
-
-
- await() -
-
-
- -
- - -
-
- cancel() -
-
-
- -
- - - - - - - - -
- -
-
- -
- - - - - -
- -
-
- -
- - -
- -
-
- ATOMIC -
-
-
-
- DEFAULT -
-
-
-
- LAZY -
-
-
- -
-
- - - - - -
-
- Deferred -
-
-
-
- delay() -
-
- -
- -
- -
- -
-
- -
- - -
- -
-
- -
- - -
-
- invoke() -
-
- -
-
- isActive -
-
-
- -
-
-
- Job -
-
-
-
- job -
-
-
-
- Job() -
-
-
-
- joinAll() -
-
-
-
- launch() -
-
- -
- -
- - - -
- -
- -
-
- plus() -
-
-
-
- promise() -
-
-
- -
- -
-
- Runnable -
-
-
- -
-
- -
- - - - -
- -
-
- -
- -
-
- yield() -
-
-
-
- -
-
- actor() -
-
-
- -
-
- -
-
- -
- - -
- -
- -
-
- -
-
-
- SUSPEND -
-
-
-
-
- Channel -
-
-
-
- Channel() -
-
-
- -
-
- -
- - - -
-
- consume() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- produce() -
-
-
- -
-
- -
-
- -
-
-
- ticker() -
-
-
- -
- -
-
- -
-
-
-
- toList() -
-
- -
-
- -
- -
-
-
- asFlow() -
-
-
- -
-
- -
-
-
- buffer() -
-
-
- -
-
- -
-
-
- catch() -
-
-
- -
-
-
- collect() -
-
- -
- -
-
-
- combine() -
-
- -
- -
-
- -
-
-
- count() -
-
-
- -
- - - - -
-
- drop() -
-
-
- -
-
-
- emitAll() -
-
-
- -
-
-
- filter() -
-
- -
- -
-
- -
-
-
- first() -
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
- Flow -
-
-
-
- flow() -
-
-
- -
-
-
- flowOf() -
-
-
-
- flowOn() -
-
-
-
- fold() -
-
-
- -
-
-
- last() -
-
-
- -
-
- -
-
-
- map() -
-
-
- -
-
- -
-
-
- merge() -
-
- - - - -
- -
-
-
- onEach() -
-
-
-
- onEmpty() -
-
-
-
- onStart() -
-
- -
- -
-
- -
-
-
- reduce() -
-
-
-
- retry() -
-
-
- -
-
- -
-
- -
-
-
- sample() -
-
-
-
- scan() -
-
-
- -
-
-
- shareIn() -
-
-
- -
-
- START -
-
-
-
- STOP -
-
- -
-
- -
-
-
- single() -
-
-
- -
-
-
- StateFlow -
-
-
-
- stateIn() -
-
-
-
- take() -
-
-
- -
-
- -
-
-
- toList() -
-
-
-
- toSet() -
-
-
- -
- - -
-
- update() -
-
-
- -
- -
- -
-
-
- zip() -
-
-
- -
- -
- -
-
-
- select() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- -
-
- Mutex -
-
-
-
- Mutex() -
-
-
-
- Semaphore -
-
-
- -
-
- -
-
- -
-
-
- -
- -
- -
- -
- -
-
- await() -
-
-
-
- future() -
-
-
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
-
- JavaFx -
-
- -
-
-
- -
- - -
- -
-
-
- await() -
-
-
-
- future() -
-
-
- -
- -
- -
-
-
- delay() -
-
-
- -
-
-
- sample() -
-
-
- -
- -
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
- -
-
-
- -
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
-
- publish() -
-
-
-
- -
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
-
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
- - - -
diff --git a/navigation.html b/navigation.html deleted file mode 100644 index 04c498b4d7..0000000000 --- a/navigation.html +++ /dev/null @@ -1,2047 +0,0 @@ -
- -
- -
- - - -
- -
-
- -
-
- -
-
-
- async() -
-
-
-
- await() -
-
-
- -
- - -
-
- cancel() -
-
-
- -
- - - - - - - - -
- -
-
- -
- - - - - -
- -
-
- -
- - -
- -
-
- ATOMIC -
-
-
-
- DEFAULT -
-
-
-
- LAZY -
-
-
- -
-
- - - - - -
-
- Deferred -
-
-
-
- delay() -
-
- -
- -
- -
- -
-
- -
- - -
- -
-
- -
- - -
-
- invoke() -
-
- -
-
- isActive -
-
-
- -
-
-
- Job -
-
-
-
- job -
-
-
-
- Job() -
-
-
-
- joinAll() -
-
-
-
- launch() -
-
- -
- -
- - - -
- -
- -
-
- plus() -
-
-
-
- promise() -
-
-
- -
- -
-
- Runnable -
-
-
- -
-
- -
- - - - -
- -
-
- -
- -
-
- yield() -
-
-
-
- -
-
- actor() -
-
-
- -
-
- -
-
- -
- - -
- -
- -
-
- -
-
-
- SUSPEND -
-
-
-
-
- Channel -
-
-
-
- Channel() -
-
-
- -
-
- -
- - - -
-
- consume() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- produce() -
-
-
- -
-
- -
-
- -
-
-
- ticker() -
-
-
- -
- -
-
- -
-
-
-
- toList() -
-
- -
-
- -
- -
-
-
- asFlow() -
-
-
- -
-
- -
-
-
- buffer() -
-
-
- -
-
- -
-
-
- catch() -
-
-
- -
-
-
- collect() -
-
- -
- -
-
-
- combine() -
-
- -
- -
-
- -
-
-
- count() -
-
-
- -
- - - - -
-
- drop() -
-
-
- -
-
-
- emitAll() -
-
-
- -
-
-
- filter() -
-
- -
- -
-
- -
-
-
- first() -
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
- Flow -
-
-
-
- flow() -
-
-
- -
-
-
- flowOf() -
-
-
-
- flowOn() -
-
-
-
- fold() -
-
-
- -
-
-
- last() -
-
-
- -
-
- -
-
-
- map() -
-
-
- -
-
- -
-
-
- merge() -
-
- - - - -
- -
-
-
- onEach() -
-
-
-
- onEmpty() -
-
-
-
- onStart() -
-
- -
- -
-
- -
-
-
- reduce() -
-
-
-
- retry() -
-
-
- -
-
- -
-
- -
-
-
- sample() -
-
-
-
- scan() -
-
-
- -
-
-
- shareIn() -
-
-
- -
-
- START -
-
-
-
- STOP -
-
- -
-
- -
-
-
- single() -
-
-
- -
-
-
- StateFlow -
-
-
-
- stateIn() -
-
-
-
- take() -
-
-
- -
-
- -
-
-
- toList() -
-
-
-
- toSet() -
-
-
- -
- - -
-
- update() -
-
-
- -
- -
- -
-
-
- zip() -
-
-
- -
- -
- -
-
-
- select() -
-
-
- -
-
- -
-
- -
-
- -
- -
- -
-
-
- -
-
- Mutex -
-
-
-
- Mutex() -
-
-
-
- Semaphore -
-
-
- -
-
- -
-
- -
-
-
- -
- -
- -
- -
- -
-
- await() -
-
-
-
- future() -
-
-
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
-
- JavaFx -
-
- -
-
-
- -
- - -
- -
-
-
- await() -
-
-
-
- future() -
-
-
- -
- -
- -
-
-
- delay() -
-
-
- -
-
-
- sample() -
-
-
- -
- -
-
-
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
- -
-
-
- -
- -
- -
-
- asFlow() -
-
-
- -
-
- -
- - - -
- -
-
- -
-
-
- collect() -
-
-
-
- publish() -
-
-
-
- -
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
-
- -
- -
- -
- - -
-
- asFlow() -
-
-
- -
-
-
- asMaybe() -
-
-
- -
-
- -
-
- -
-
-
- await() -
-
-
- -
- - - -
- -
-
- -
- -
-
- collect() -
-
-
- -
-
- -
-
-
- rxMaybe() -
-
-
- -
-
- -
- -
-
- - - -