├── .github
└── ISSUE_TEMPLATE
│ ├── bug_report.md
│ ├── config.yml
│ ├── design_considerations.md
│ ├── feature_request.md
│ ├── guide.md
│ └── rc_feedback.md
├── .gitignore
├── .idea
├── codeStyleSettings.xml
├── codeStyles
│ ├── Project.xml
│ └── codeStyleConfig.xml
├── copyright
│ └── profiles_settings.xml
├── dictionaries
│ └── shared.xml
├── icon.png
└── vcs.xml
├── CHANGES.md
├── CHANGES_UP_TO_1.7.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE.txt
├── README.md
├── RELEASE.md
├── benchmarks
├── build.gradle.kts
├── scripts
│ └── generate_plots_flow_flatten_merge.py
└── src
│ ├── jmh
│ ├── java
│ │ └── benchmarks
│ │ │ └── flow
│ │ │ └── scrabble
│ │ │ ├── RxJava2PlaysScrabble.java
│ │ │ ├── RxJava2PlaysScrabbleOpt.java
│ │ │ └── optimizations
│ │ │ ├── FlowableCharSequence.java
│ │ │ ├── FlowableSplit.java
│ │ │ └── StringFlowable.java
│ ├── kotlin
│ │ └── benchmarks
│ │ │ ├── ChannelSinkBenchmark.kt
│ │ │ ├── ChannelSinkDepthBenchmark.kt
│ │ │ ├── ChannelSinkNoAllocationsBenchmark.kt
│ │ │ ├── ParametrizedDispatcherBase.kt
│ │ │ ├── SequentialSemaphoreBenchmark.kt
│ │ │ ├── akka
│ │ │ ├── PingPongAkkaBenchmark.kt
│ │ │ └── StatefulActorAkkaBenchmark.kt
│ │ │ ├── debug
│ │ │ └── DebugSequenceOverheadBenchmark.kt
│ │ │ ├── flow
│ │ │ ├── CombineFlowsBenchmark.kt
│ │ │ ├── CombineTwoFlowsBenchmark.kt
│ │ │ ├── FlatMapMergeBenchmark.kt
│ │ │ ├── FlowFlattenMergeBenchmark.kt
│ │ │ ├── NumbersBenchmark.kt
│ │ │ ├── SafeFlowBenchmark.kt
│ │ │ ├── TakeBenchmark.kt
│ │ │ └── scrabble
│ │ │ │ ├── FlowPlaysScrabbleBase.kt
│ │ │ │ ├── FlowPlaysScrabbleOpt.kt
│ │ │ │ ├── IterableSpliterator.kt
│ │ │ │ ├── README.md
│ │ │ │ ├── ReactorPlaysScrabble.kt
│ │ │ │ ├── SaneFlowPlaysScrabble.kt
│ │ │ │ ├── SequencePlaysScrabble.kt
│ │ │ │ └── ShakespearePlaysScrabble.kt
│ │ │ └── scheduler
│ │ │ ├── DispatchersContextSwitchBenchmark.kt
│ │ │ ├── ForkJoinBenchmark.kt
│ │ │ ├── LaunchBenchmark.kt
│ │ │ ├── StatefulAwaitsBenchmark.kt
│ │ │ └── actors
│ │ │ ├── ConcurrentStatefulActorBenchmark.kt
│ │ │ ├── CycledActorsBenchmark.kt
│ │ │ ├── PingPongActorBenchmark.kt
│ │ │ ├── PingPongWithBlockingContext.kt
│ │ │ └── StatefulActorBenchmark.kt
│ └── resources
│ │ ├── ospd.txt.gz
│ │ └── words.shakespeare.txt.gz
│ └── main
│ └── kotlin
│ └── benchmarks
│ └── common
│ └── BenchmarkUtils.kt
├── build.gradle.kts
├── buildSrc
├── build.gradle.kts
├── settings.gradle.kts
└── src
│ └── main
│ └── kotlin
│ ├── AuxBuildConfiguration.kt
│ ├── CacheRedirector.kt
│ ├── CommunityProjectsBuild.kt
│ ├── Dokka.kt
│ ├── GlobalKotlinCompilerOptions.kt
│ ├── Idea.kt
│ ├── Java9Modularity.kt
│ ├── Platform.kt
│ ├── Projects.kt
│ ├── Publishing.kt
│ ├── SourceSets.kt
│ ├── UnpackAar.kt
│ ├── VersionFile.kt
│ ├── animalsniffer-jvm-conventions.gradle.kts
│ ├── animalsniffer-multiplatform-conventions.gradle.kts
│ ├── bom-conventions.gradle.kts
│ ├── configure-compilation-conventions.gradle.kts
│ ├── dokka-conventions.gradle.kts
│ ├── java-modularity-conventions.gradle.kts
│ ├── knit-conventions.gradle.kts
│ ├── kotlin-jvm-conventions.gradle.kts
│ ├── kotlin-multiplatform-conventions.gradle.kts
│ ├── kover-conventions.gradle.kts
│ ├── pub-conventions.gradle.kts
│ ├── source-set-conventions.gradle.kts
│ └── version-file-conventions.gradle.kts
├── bump-version.sh
├── coroutines-guide.md
├── docs
├── basics.md
├── cancellation-and-timeouts.md
├── cfg
│ └── buildprofiles.xml
├── channels.md
├── compatibility.md
├── composing-suspending-functions.md
├── coroutine-context-and-dispatchers.md
├── coroutines-guide.md
├── debugging.md
├── exception-handling.md
├── flow.md
├── images
│ ├── after.png
│ ├── before.png
│ ├── coroutine-breakpoint.png
│ ├── coroutine-debug-1.png
│ ├── coroutine-debug-2.png
│ ├── coroutine-debug-3.png
│ ├── coroutine-idea-debugging-1.png
│ ├── coroutines-and-channels
│ │ ├── aggregate.png
│ │ ├── background.png
│ │ ├── blocking.png
│ │ ├── buffered-channel.png
│ │ ├── callbacks.png
│ │ ├── concurrency.png
│ │ ├── conflated-channel.gif
│ │ ├── generating-token.png
│ │ ├── initial-window.png
│ │ ├── loading.gif
│ │ ├── progress-and-concurrency.png
│ │ ├── progress.png
│ │ ├── rendezvous-channel.png
│ │ ├── run-configuration.png
│ │ ├── suspend-requests.png
│ │ ├── suspension-process.gif
│ │ ├── time-comparison.png
│ │ ├── unlimited-channel.png
│ │ ├── using-channel-many-coroutines.png
│ │ └── using-channel.png
│ ├── flow-breakpoint.png
│ ├── flow-build-project.png
│ ├── flow-debug-1.png
│ ├── flow-debug-2.png
│ ├── flow-debug-3.png
│ ├── flow-debug-4.png
│ ├── flow-debug-project.png
│ ├── flow-resume-debug.png
│ ├── new-gradle-project-jvm.png
│ └── variable-optimised-out.png
├── kc.tree
├── knit.code.include
├── knit.test.template
├── select-expression.md
├── shared-mutable-state-and-concurrency.md
├── topics
│ ├── cancellation-and-timeouts.md
│ ├── channels.md
│ ├── compatibility.md
│ ├── composing-suspending-functions.md
│ ├── coroutine-context-and-dispatchers.md
│ ├── coroutines-and-channels.md
│ ├── coroutines-basics.md
│ ├── coroutines-guide.md
│ ├── debug-coroutines-with-idea.md
│ ├── debug-flow-with-idea.md
│ ├── debugging.md
│ ├── exception-handling.md
│ ├── flow.md
│ ├── knit.properties
│ ├── select-expression.md
│ └── shared-mutable-state-and-concurrency.md
└── writerside.cfg
├── dokka-templates
└── README.md
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── integration-testing
├── .gitignore
├── README.md
├── build.gradle.kts
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── java8Test
│ ├── build.gradle.kts
│ └── src
│ │ └── test
│ │ └── kotlin
│ │ └── JUnit5TimeoutCompilation.kt
├── jpmsTest
│ ├── build.gradle.kts
│ └── src
│ │ └── debugDynamicAgentJpmsTest
│ │ ├── java
│ │ └── module-info.java
│ │ └── kotlin
│ │ └── DynamicAttachDebugJpmsTest.kt
├── settings.gradle.kts
├── smokeTest
│ ├── build.gradle.kts
│ └── src
│ │ ├── commonMain
│ │ └── kotlin
│ │ │ └── Sample.kt
│ │ └── commonTest
│ │ └── kotlin
│ │ └── SampleTest.kt
└── src
│ ├── coreAgentTest
│ └── kotlin
│ │ └── CoreAgentTest.kt
│ ├── debugAgentTest
│ └── kotlin
│ │ ├── DebugAgentTest.kt
│ │ ├── DebugProbes.kt
│ │ └── PrecompiledDebugProbesTest.kt
│ ├── debugDynamicAgentTest
│ └── kotlin
│ │ └── DynamicAttachDebugTest.kt
│ ├── jvmCoreTest
│ └── kotlin
│ │ ├── Jdk8InCoreIntegration.kt
│ │ └── ListAllCoroutineThrowableSubclassesTest.kt
│ └── mavenTest
│ └── kotlin
│ ├── MavenPublicationAtomicfuValidator.kt
│ ├── MavenPublicationMetaInfValidator.kt
│ └── MavenPublicationVersionValidator.kt
├── integration
├── README.md
├── kotlinx-coroutines-guava
│ ├── README.md
│ ├── api
│ │ └── kotlinx-coroutines-guava.api
│ ├── build.gradle.kts
│ ├── package.list
│ ├── src
│ │ ├── ListenableFuture.kt
│ │ └── module-info.java
│ └── test
│ │ ├── FutureAsDeferredUnhandledCompletionExceptionTest.kt
│ │ ├── ListenableFutureExceptionsTest.kt
│ │ ├── ListenableFutureTest.kt
│ │ └── ListenableFutureToStringTest.kt
├── kotlinx-coroutines-jdk8
│ ├── README.md
│ ├── api
│ │ └── kotlinx-coroutines-jdk8.api
│ ├── build.gradle.kts
│ └── src
│ │ └── module-info.java
├── kotlinx-coroutines-play-services
│ ├── README.md
│ ├── api
│ │ └── kotlinx-coroutines-play-services.api
│ ├── build.gradle.kts
│ ├── package.list
│ ├── src
│ │ └── Tasks.kt
│ └── test
│ │ ├── FakeAndroid.kt
│ │ └── TaskTest.kt
└── kotlinx-coroutines-slf4j
│ ├── README.md
│ ├── api
│ └── kotlinx-coroutines-slf4j.api
│ ├── build.gradle.kts
│ ├── package.list
│ ├── src
│ ├── MDCContext.kt
│ └── module-info.java
│ ├── test-resources
│ └── logback-test.xml
│ └── test
│ └── MDCContextTest.kt
├── knit.properties
├── kotlinx-coroutines-bom
└── build.gradle.kts
├── kotlinx-coroutines-core
├── README.md
├── api
│ ├── kotlinx-coroutines-core.api
│ └── kotlinx-coroutines-core.klib.api
├── benchmarks
│ ├── README.md
│ ├── jvm
│ │ └── kotlin
│ │ │ └── kotlinx
│ │ │ └── coroutines
│ │ │ ├── BenchmarkUtils.kt
│ │ │ ├── SemaphoreBenchmark.kt
│ │ │ ├── channels
│ │ │ ├── ChannelProducerConsumerBenchmark.kt
│ │ │ ├── SelectBenchmark.kt
│ │ │ ├── SimpleChannel.kt
│ │ │ └── SimpleChannelBenchmark.kt
│ │ │ └── flow
│ │ │ └── TakeWhileBenchmark.kt
│ └── main
│ │ └── kotlin
│ │ └── SharedFlowBaseline.kt
├── build.gradle.kts
├── common
│ ├── README.md
│ ├── src
│ │ ├── AbstractCoroutine.kt
│ │ ├── Annotations.kt
│ │ ├── Await.kt
│ │ ├── Builders.common.kt
│ │ ├── CancellableContinuation.kt
│ │ ├── CancellableContinuationImpl.kt
│ │ ├── CloseableCoroutineDispatcher.kt
│ │ ├── CompletableDeferred.kt
│ │ ├── CompletableJob.kt
│ │ ├── CompletionHandler.common.kt
│ │ ├── CompletionState.kt
│ │ ├── CoroutineContext.common.kt
│ │ ├── CoroutineDispatcher.kt
│ │ ├── CoroutineExceptionHandler.kt
│ │ ├── CoroutineName.kt
│ │ ├── CoroutineScope.kt
│ │ ├── CoroutineStart.kt
│ │ ├── Debug.common.kt
│ │ ├── Deferred.kt
│ │ ├── Delay.kt
│ │ ├── Dispatchers.common.kt
│ │ ├── EventLoop.common.kt
│ │ ├── Exceptions.common.kt
│ │ ├── Guidance.kt
│ │ ├── Job.kt
│ │ ├── JobSupport.kt
│ │ ├── MainCoroutineDispatcher.kt
│ │ ├── NonCancellable.kt
│ │ ├── Runnable.common.kt
│ │ ├── SchedulerTask.common.kt
│ │ ├── Supervisor.kt
│ │ ├── Timeout.kt
│ │ ├── Unconfined.kt
│ │ ├── Waiter.kt
│ │ ├── Yield.kt
│ │ ├── channels
│ │ │ ├── Broadcast.kt
│ │ │ ├── BroadcastChannel.kt
│ │ │ ├── BufferOverflow.kt
│ │ │ ├── BufferedChannel.kt
│ │ │ ├── Channel.kt
│ │ │ ├── ChannelCoroutine.kt
│ │ │ ├── Channels.common.kt
│ │ │ ├── ConflatedBufferedChannel.kt
│ │ │ ├── Deprecated.kt
│ │ │ └── Produce.kt
│ │ ├── flow
│ │ │ ├── Builders.kt
│ │ │ ├── Channels.kt
│ │ │ ├── Flow.kt
│ │ │ ├── FlowCollector.kt
│ │ │ ├── Migration.kt
│ │ │ ├── SharedFlow.kt
│ │ │ ├── SharingStarted.kt
│ │ │ ├── StateFlow.kt
│ │ │ ├── internal
│ │ │ │ ├── AbstractSharedFlow.kt
│ │ │ │ ├── ChannelFlow.kt
│ │ │ │ ├── Combine.kt
│ │ │ │ ├── FlowCoroutine.kt
│ │ │ │ ├── FlowExceptions.common.kt
│ │ │ │ ├── Merge.kt
│ │ │ │ ├── NopCollector.kt
│ │ │ │ ├── NullSurrogate.kt
│ │ │ │ ├── SafeCollector.common.kt
│ │ │ │ └── SendingCollector.kt
│ │ │ ├── operators
│ │ │ │ ├── Context.kt
│ │ │ │ ├── Delay.kt
│ │ │ │ ├── Distinct.kt
│ │ │ │ ├── Emitters.kt
│ │ │ │ ├── Errors.kt
│ │ │ │ ├── Limit.kt
│ │ │ │ ├── Lint.kt
│ │ │ │ ├── Merge.kt
│ │ │ │ ├── Share.kt
│ │ │ │ ├── Transform.kt
│ │ │ │ └── Zip.kt
│ │ │ └── terminal
│ │ │ │ ├── Collect.kt
│ │ │ │ ├── Collection.kt
│ │ │ │ ├── Count.kt
│ │ │ │ ├── Logic.kt
│ │ │ │ └── Reduce.kt
│ │ ├── internal
│ │ │ ├── Concurrent.common.kt
│ │ │ ├── ConcurrentLinkedList.kt
│ │ │ ├── CoroutineExceptionHandlerImpl.common.kt
│ │ │ ├── DispatchedContinuation.kt
│ │ │ ├── DispatchedTask.kt
│ │ │ ├── InlineList.kt
│ │ │ ├── InternalAnnotations.common.kt
│ │ │ ├── LimitedDispatcher.kt
│ │ │ ├── LocalAtomics.common.kt
│ │ │ ├── LockFreeLinkedList.common.kt
│ │ │ ├── LockFreeTaskQueue.kt
│ │ │ ├── MainDispatcherFactory.kt
│ │ │ ├── NamedDispatcher.kt
│ │ │ ├── OnUndeliveredElement.kt
│ │ │ ├── ProbesSupport.common.kt
│ │ │ ├── Scopes.kt
│ │ │ ├── StackTraceRecovery.common.kt
│ │ │ ├── Symbol.kt
│ │ │ ├── Synchronized.common.kt
│ │ │ ├── SystemProps.common.kt
│ │ │ ├── ThreadContext.common.kt
│ │ │ ├── ThreadLocal.common.kt
│ │ │ └── ThreadSafeHeap.kt
│ │ ├── intrinsics
│ │ │ ├── Cancellable.kt
│ │ │ └── Undispatched.kt
│ │ ├── selects
│ │ │ ├── OnTimeout.kt
│ │ │ ├── Select.kt
│ │ │ ├── SelectOld.kt
│ │ │ ├── SelectUnbiased.kt
│ │ │ └── WhileSelect.kt
│ │ └── sync
│ │ │ ├── Mutex.kt
│ │ │ └── Semaphore.kt
│ └── test
│ │ ├── AbstractCoroutineTest.kt
│ │ ├── AsyncLazyTest.kt
│ │ ├── AsyncTest.kt
│ │ ├── AtomicCancellationCommonTest.kt
│ │ ├── AwaitCancellationTest.kt
│ │ ├── AwaitTest.kt
│ │ ├── BuilderContractsTest.kt
│ │ ├── CancellableContinuationHandlersTest.kt
│ │ ├── CancellableContinuationTest.kt
│ │ ├── CancellableResumeOldTest.kt
│ │ ├── CancellableResumeTest.kt
│ │ ├── CancelledParentAttachTest.kt
│ │ ├── CompletableDeferredTest.kt
│ │ ├── CompletableJobTest.kt
│ │ ├── CoroutineDispatcherOperatorFunInvokeTest.kt
│ │ ├── CoroutineExceptionHandlerTest.kt
│ │ ├── CoroutineScopeTest.kt
│ │ ├── CoroutinesTest.kt
│ │ ├── DelayDurationTest.kt
│ │ ├── DelayTest.kt
│ │ ├── DispatchedContinuationTest.kt
│ │ ├── DurationToMillisTest.kt
│ │ ├── EmptyContext.kt
│ │ ├── FailedJobTest.kt
│ │ ├── ImmediateYieldTest.kt
│ │ ├── JobExtensionsTest.kt
│ │ ├── JobStatesTest.kt
│ │ ├── JobTest.kt
│ │ ├── LaunchLazyTest.kt
│ │ ├── LimitedParallelismSharedTest.kt
│ │ ├── NonCancellableTest.kt
│ │ ├── ParentCancellationTest.kt
│ │ ├── SupervisorTest.kt
│ │ ├── UnconfinedCancellationTest.kt
│ │ ├── UnconfinedTest.kt
│ │ ├── UndispatchedResultTest.kt
│ │ ├── WithContextTest.kt
│ │ ├── WithTimeoutDurationTest.kt
│ │ ├── WithTimeoutOrNullDurationTest.kt
│ │ ├── WithTimeoutOrNullTest.kt
│ │ ├── WithTimeoutTest.kt
│ │ ├── channels
│ │ ├── BasicOperationsTest.kt
│ │ ├── BroadcastChannelFactoryTest.kt
│ │ ├── BroadcastTest.kt
│ │ ├── BufferedBroadcastChannelTest.kt
│ │ ├── BufferedChannelTest.kt
│ │ ├── ChannelBufferOverflowTest.kt
│ │ ├── ChannelFactoryTest.kt
│ │ ├── ChannelReceiveCatchingTest.kt
│ │ ├── ChannelUndeliveredElementFailureTest.kt
│ │ ├── ChannelUndeliveredElementTest.kt
│ │ ├── ChannelsTest.kt
│ │ ├── ConflatedBroadcastChannelTest.kt
│ │ ├── ConflatedChannelTest.kt
│ │ ├── ConsumeTest.kt
│ │ ├── ProduceConsumeTest.kt
│ │ ├── ProduceTest.kt
│ │ ├── RendezvousChannelTest.kt
│ │ ├── SendReceiveStressTest.kt
│ │ ├── TestBroadcastChannelKind.kt
│ │ ├── TestChannelKind.kt
│ │ └── UnlimitedChannelTest.kt
│ │ ├── flow
│ │ ├── BuildersTest.kt
│ │ ├── FlowInvariantsTest.kt
│ │ ├── IdFlowTest.kt
│ │ ├── NamedDispatchers.kt
│ │ ├── SafeFlowTest.kt
│ │ ├── VirtualTime.kt
│ │ ├── channels
│ │ │ ├── ChannelBuildersFlowTest.kt
│ │ │ ├── ChannelFlowTest.kt
│ │ │ └── FlowCallbackTest.kt
│ │ ├── internal
│ │ │ └── FlowScopeTest.kt
│ │ ├── operators
│ │ │ ├── BooleanTerminationTest.kt
│ │ │ ├── BufferConflationTest.kt
│ │ │ ├── BufferTest.kt
│ │ │ ├── CancellableTest.kt
│ │ │ ├── CatchTest.kt
│ │ │ ├── ChunkedTest.kt
│ │ │ ├── CombineParametersTest.kt
│ │ │ ├── CombineTest.kt
│ │ │ ├── ConflateTest.kt
│ │ │ ├── DebounceTest.kt
│ │ │ ├── DistinctUntilChangedTest.kt
│ │ │ ├── DropTest.kt
│ │ │ ├── DropWhileTest.kt
│ │ │ ├── FilterTest.kt
│ │ │ ├── FilterTrivialTest.kt
│ │ │ ├── FlatMapBaseTest.kt
│ │ │ ├── FlatMapConcatTest.kt
│ │ │ ├── FlatMapLatestTest.kt
│ │ │ ├── FlatMapMergeBaseTest.kt
│ │ │ ├── FlatMapMergeFastPathTest.kt
│ │ │ ├── FlatMapMergeTest.kt
│ │ │ ├── FlattenConcatTest.kt
│ │ │ ├── FlattenMergeTest.kt
│ │ │ ├── FlowContextOptimizationsTest.kt
│ │ │ ├── FlowOnTest.kt
│ │ │ ├── IndexedTest.kt
│ │ │ ├── LintTest.kt
│ │ │ ├── MapNotNullTest.kt
│ │ │ ├── MapTest.kt
│ │ │ ├── MergeTest.kt
│ │ │ ├── OnCompletionTest.kt
│ │ │ ├── OnEachTest.kt
│ │ │ ├── OnEmptyTest.kt
│ │ │ ├── OnStartTest.kt
│ │ │ ├── RetryTest.kt
│ │ │ ├── SampleTest.kt
│ │ │ ├── ScanTest.kt
│ │ │ ├── TakeTest.kt
│ │ │ ├── TakeWhileTest.kt
│ │ │ ├── TimeoutTest.kt
│ │ │ ├── TransformLatestTest.kt
│ │ │ ├── TransformTest.kt
│ │ │ ├── TransformWhileTest.kt
│ │ │ └── ZipTest.kt
│ │ ├── sharing
│ │ │ ├── ShareInBufferTest.kt
│ │ │ ├── ShareInConflationTest.kt
│ │ │ ├── ShareInFusionTest.kt
│ │ │ ├── ShareInTest.kt
│ │ │ ├── SharedFlowScenarioTest.kt
│ │ │ ├── SharedFlowTest.kt
│ │ │ ├── SharingStartedTest.kt
│ │ │ ├── SharingStartedWhileSubscribedTest.kt
│ │ │ ├── StateFlowTest.kt
│ │ │ └── StateInTest.kt
│ │ └── terminal
│ │ │ ├── CollectLatestTest.kt
│ │ │ ├── CountTest.kt
│ │ │ ├── FirstTest.kt
│ │ │ ├── FoldTest.kt
│ │ │ ├── LastTest.kt
│ │ │ ├── LaunchInTest.kt
│ │ │ ├── ReduceTest.kt
│ │ │ ├── SingleTest.kt
│ │ │ └── ToCollectionTest.kt
│ │ ├── selects
│ │ ├── SelectBiasTest.kt
│ │ ├── SelectBufferedChannelTest.kt
│ │ ├── SelectDeferredTest.kt
│ │ ├── SelectJobTest.kt
│ │ ├── SelectLoopTest.kt
│ │ ├── SelectMutexTest.kt
│ │ ├── SelectOldTest.kt
│ │ ├── SelectRendezvousChannelTest.kt
│ │ ├── SelectTimeoutDurationTest.kt
│ │ ├── SelectTimeoutTest.kt
│ │ └── SelectUnlimitedChannelTest.kt
│ │ └── sync
│ │ ├── MutexTest.kt
│ │ └── SemaphoreTest.kt
├── concurrent
│ ├── src
│ │ ├── Builders.concurrent.kt
│ │ ├── Dispatchers.kt
│ │ ├── MultithreadedDispatchers.common.kt
│ │ ├── channels
│ │ │ └── Channels.kt
│ │ └── internal
│ │ │ ├── LockFreeLinkedList.kt
│ │ │ └── OnDemandAllocatingPool.kt
│ └── test
│ │ ├── AbstractDispatcherConcurrencyTest.kt
│ │ ├── AtomicCancellationTest.kt
│ │ ├── CommonThreadLocalTest.kt
│ │ ├── ConcurrentExceptionsStressTest.kt
│ │ ├── ConcurrentTestUtilities.common.kt
│ │ ├── DefaultDispatchersConcurrencyTest.kt
│ │ ├── JobStructuredJoinStressTest.kt
│ │ ├── LimitedParallelismConcurrentTest.kt
│ │ ├── MultithreadedDispatcherStressTest.kt
│ │ ├── RunBlockingTest.kt
│ │ ├── channels
│ │ ├── BroadcastChannelSubStressTest.kt
│ │ ├── ChannelCancelUndeliveredElementStressTest.kt
│ │ ├── ConflatedBroadcastChannelNotifyStressTest.kt
│ │ └── TrySendBlockingTest.kt
│ │ ├── flow
│ │ ├── CombineStressTest.kt
│ │ ├── FlowCancellationTest.kt
│ │ ├── StateFlowCommonStressTest.kt
│ │ └── StateFlowUpdateCommonTest.kt
│ │ ├── selects
│ │ ├── SelectChannelStressTest.kt
│ │ └── SelectMutexStressTest.kt
│ │ └── sync
│ │ ├── MutexStressTest.kt
│ │ └── SemaphoreStressTest.kt
├── js
│ ├── src
│ │ ├── CoroutineContext.kt
│ │ ├── Debug.kt
│ │ ├── JSDispatcher.kt
│ │ ├── Promise.kt
│ │ ├── Window.kt
│ │ └── internal
│ │ │ ├── CopyOnWriteList.kt
│ │ │ └── CoroutineExceptionHandlerImpl.kt
│ └── test
│ │ └── PromiseTest.kt
├── jsAndWasmJsShared
│ ├── src
│ │ ├── EventLoop.kt
│ │ └── internal
│ │ │ └── JSDispatcher.kt
│ └── test
│ │ ├── MessageQueueTest.kt
│ │ └── SetTimeoutDispatcherTest.kt
├── jsAndWasmShared
│ ├── src
│ │ ├── CloseableCoroutineDispatcher.kt
│ │ ├── CoroutineContext.kt
│ │ ├── Dispatchers.kt
│ │ ├── Exceptions.kt
│ │ ├── Runnable.kt
│ │ ├── SchedulerTask.kt
│ │ ├── flow
│ │ │ └── internal
│ │ │ │ ├── FlowExceptions.kt
│ │ │ │ └── SafeCollector.kt
│ │ └── internal
│ │ │ ├── Concurrent.kt
│ │ │ ├── CoroutineExceptionHandlerImpl.kt
│ │ │ ├── LinkedList.kt
│ │ │ ├── LocalAtomics.kt
│ │ │ ├── ProbesSupport.kt
│ │ │ ├── StackTraceRecovery.kt
│ │ │ ├── Synchronized.kt
│ │ │ ├── SystemProps.kt
│ │ │ ├── ThreadContext.kt
│ │ │ └── ThreadLocal.kt
│ └── test
│ │ ├── ImmediateDispatcherTest.kt
│ │ └── internal
│ │ └── LinkedListTest.kt
├── jvm
│ ├── resources
│ │ ├── DebugProbesKt.bin
│ │ └── META-INF
│ │ │ ├── com.android.tools
│ │ │ ├── proguard
│ │ │ │ └── coroutines.pro
│ │ │ └── r8
│ │ │ │ └── coroutines.pro
│ │ │ └── proguard
│ │ │ └── coroutines.pro
│ ├── src
│ │ ├── AbstractTimeSource.kt
│ │ ├── Builders.kt
│ │ ├── CoroutineContext.kt
│ │ ├── Debug.kt
│ │ ├── DebugStrings.kt
│ │ ├── DefaultExecutor.kt
│ │ ├── Dispatchers.kt
│ │ ├── EventLoop.kt
│ │ ├── Exceptions.kt
│ │ ├── Executors.kt
│ │ ├── Future.kt
│ │ ├── Interruptible.kt
│ │ ├── Runnable.kt
│ │ ├── SchedulerTask.kt
│ │ ├── ThreadContextElement.kt
│ │ ├── ThreadPoolDispatcher.kt
│ │ ├── channels
│ │ │ ├── Actor.kt
│ │ │ └── TickerChannels.kt
│ │ ├── debug
│ │ │ ├── CoroutineDebugging.kt
│ │ │ └── internal
│ │ │ │ ├── AgentInstallationType.kt
│ │ │ │ ├── AgentPremain.kt
│ │ │ │ ├── ConcurrentWeakMap.kt
│ │ │ │ ├── DebugCoroutineInfo.kt
│ │ │ │ ├── DebugCoroutineInfoImpl.kt
│ │ │ │ ├── DebugProbes.kt
│ │ │ │ ├── DebugProbesImpl.kt
│ │ │ │ ├── DebuggerInfo.kt
│ │ │ │ └── StackTraceFrame.kt
│ │ ├── flow
│ │ │ └── internal
│ │ │ │ ├── FlowExceptions.kt
│ │ │ │ └── SafeCollector.kt
│ │ ├── future
│ │ │ └── Future.kt
│ │ ├── internal
│ │ │ ├── Concurrent.kt
│ │ │ ├── CoroutineExceptionHandlerImpl.kt
│ │ │ ├── ExceptionsConstructor.kt
│ │ │ ├── FastServiceLoader.kt
│ │ │ ├── InternalAnnotations.kt
│ │ │ ├── LocalAtomics.kt
│ │ │ ├── MainDispatchers.kt
│ │ │ ├── ProbesSupport.kt
│ │ │ ├── ResizableAtomicArray.kt
│ │ │ ├── StackTraceRecovery.kt
│ │ │ ├── Synchronized.kt
│ │ │ ├── SystemProps.kt
│ │ │ ├── ThreadContext.kt
│ │ │ └── ThreadLocal.kt
│ │ ├── module-info.java
│ │ ├── scheduling
│ │ │ ├── CoroutineScheduler.kt
│ │ │ ├── Dispatcher.kt
│ │ │ ├── Tasks.kt
│ │ │ └── WorkQueue.kt
│ │ ├── stream
│ │ │ └── Stream.kt
│ │ └── time
│ │ │ └── Time.kt
│ ├── test-resources
│ │ └── stacktraces
│ │ │ ├── channels
│ │ │ ├── testOfferFromScope.txt
│ │ │ ├── testOfferWithContextWrapped.txt
│ │ │ ├── testOfferWithCurrentContext.txt
│ │ │ ├── testReceiveFromChannel.txt
│ │ │ ├── testReceiveFromClosedChannel.txt
│ │ │ ├── testSendFromScope.txt
│ │ │ ├── testSendToChannel.txt
│ │ │ └── testSendToClosedChannel.txt
│ │ │ ├── resume-mode
│ │ │ ├── testEventLoopDispatcher.txt
│ │ │ ├── testEventLoopDispatcherSuspending.txt
│ │ │ ├── testNestedEventLoopChangedContext.txt
│ │ │ ├── testNestedEventLoopChangedContextSuspending.txt
│ │ │ ├── testNestedEventLoopDispatcher.txt
│ │ │ ├── testNestedEventLoopDispatcherSuspending.txt
│ │ │ ├── testNestedUnconfined.txt
│ │ │ ├── testNestedUnconfinedChangedContext.txt
│ │ │ ├── testNestedUnconfinedChangedContextSuspending.txt
│ │ │ ├── testNestedUnconfinedSuspending.txt
│ │ │ ├── testUnconfined.txt
│ │ │ └── testUnconfinedSuspending.txt
│ │ │ ├── select
│ │ │ ├── testSelectCompletedAwait.txt
│ │ │ ├── testSelectJoin.txt
│ │ │ └── testSelectOnReceive.txt
│ │ │ └── timeout
│ │ │ ├── testStacktraceIsRecoveredFromLexicalBlockWhenTriggeredByChild.txt
│ │ │ ├── testStacktraceIsRecoveredFromSuspensionPoint.txt
│ │ │ └── testStacktraceIsRecoveredFromSuspensionPointWithChild.txt
│ └── test
│ │ ├── AbstractLincheckTest.kt
│ │ ├── AsyncJvmTest.kt
│ │ ├── AwaitJvmTest.kt
│ │ ├── AwaitStressTest.kt
│ │ ├── CancellableContinuationJvmTest.kt
│ │ ├── CancellableContinuationResumeCloseStressTest.kt
│ │ ├── CancelledAwaitStressTest.kt
│ │ ├── ConcurrentTestUtilities.kt
│ │ ├── CoroutinesJvmTest.kt
│ │ ├── DebugThreadNameTest.kt
│ │ ├── DefaultExecutorStressTest.kt
│ │ ├── DelayJvmTest.kt
│ │ ├── DispatcherKeyTest.kt
│ │ ├── DispatchersToStringTest.kt
│ │ ├── EventLoopsTest.kt
│ │ ├── ExecutorAsCoroutineDispatcherDelayTest.kt
│ │ ├── ExecutorsTest.kt
│ │ ├── FailFastOnStartTest.kt
│ │ ├── FailingCoroutinesMachineryTest.kt
│ │ ├── IODispatcherTest.kt
│ │ ├── IntellijIdeaDebuggerEvaluatorCompatibilityTest.kt
│ │ ├── JobActivationStressTest.kt
│ │ ├── JobCancellationExceptionSerializerTest.kt
│ │ ├── JobChildStressTest.kt
│ │ ├── JobDisposeStressTest.kt
│ │ ├── JobHandlersUpgradeStressTest.kt
│ │ ├── JobOnCompletionStressTest.kt
│ │ ├── JobStressTest.kt
│ │ ├── JoinStressTest.kt
│ │ ├── LimitedParallelismStressTest.kt
│ │ ├── LimitedParallelismUnhandledExceptionTest.kt
│ │ ├── MemoryFootprintTest.kt
│ │ ├── MultithreadedDispatchersJvmTest.kt
│ │ ├── MutexCancellationStressTest.kt
│ │ ├── NoParamAssertionsTest.kt
│ │ ├── RejectedExecutionTest.kt
│ │ ├── ReusableCancellableContinuationInvariantStressTest.kt
│ │ ├── ReusableCancellableContinuationLeakStressTest.kt
│ │ ├── ReusableCancellableContinuationTest.kt
│ │ ├── ReusableContinuationStressTest.kt
│ │ ├── RunBlockingJvmTest.kt
│ │ ├── RunInterruptibleStressTest.kt
│ │ ├── RunInterruptibleTest.kt
│ │ ├── TestBaseTest.kt
│ │ ├── ThreadContextElementRestoreTest.kt
│ │ ├── ThreadContextElementTest.kt
│ │ ├── ThreadContextMutableCopiesTest.kt
│ │ ├── ThreadContextOrderTest.kt
│ │ ├── ThreadLocalStressTest.kt
│ │ ├── ThreadLocalTest.kt
│ │ ├── ThreadLocalsLeaksTest.kt
│ │ ├── UnconfinedConcurrentStressTest.kt
│ │ ├── VirtualTimeSource.kt
│ │ ├── WithDefaultContextTest.kt
│ │ ├── WithTimeoutChildDispatchStressTest.kt
│ │ ├── WithTimeoutOrNullJvmTest.kt
│ │ ├── WithTimeoutOrNullThreadDispatchTest.kt
│ │ ├── WithTimeoutThreadDispatchTest.kt
│ │ ├── channels
│ │ ├── ActorLazyTest.kt
│ │ ├── ActorTest.kt
│ │ ├── BroadcastChannelLeakTest.kt
│ │ ├── BroadcastChannelMultiReceiveStressTest.kt
│ │ ├── BufferedChannelStressTest.kt
│ │ ├── CancelledChannelLeakTest.kt
│ │ ├── ChannelMemoryLeakStressTest.kt
│ │ ├── ChannelSelectStressTest.kt
│ │ ├── ChannelSendReceiveStressTest.kt
│ │ ├── ChannelUndeliveredElementSelectOldStressTest.kt
│ │ ├── ChannelUndeliveredElementStressTest.kt
│ │ ├── ConflatedChannelCloseStressTest.kt
│ │ ├── DoubleChannelCloseStressTest.kt
│ │ ├── InvokeOnCloseStressTest.kt
│ │ ├── ProduceConsumeJvmTest.kt
│ │ ├── SendReceiveJvmStressTest.kt
│ │ ├── SimpleSendReceiveJvmTest.kt
│ │ ├── TickerChannelCommonTest.kt
│ │ └── TickerChannelTest.kt
│ │ ├── examples
│ │ ├── example-delay-01.kt
│ │ ├── example-delay-02.kt
│ │ ├── example-delay-03.kt
│ │ ├── example-delay-duration-01.kt
│ │ ├── example-delay-duration-02.kt
│ │ ├── example-delay-duration-03.kt
│ │ ├── example-timeout-duration-01.kt
│ │ └── test
│ │ │ └── FlowDelayTest.kt
│ │ ├── exceptions
│ │ ├── CoroutineExceptionHandlerJvmTest.kt
│ │ ├── FlowSuppressionTest.kt
│ │ ├── JobBasicCancellationTest.kt
│ │ ├── JobExceptionHandlingTest.kt
│ │ ├── JobExceptionsStressTest.kt
│ │ ├── JobNestedExceptionsTest.kt
│ │ ├── ProduceExceptionsTest.kt
│ │ ├── StackTraceRecoveryChannelsTest.kt
│ │ ├── StackTraceRecoveryCustomExceptionsTest.kt
│ │ ├── StackTraceRecoveryNestedScopesTest.kt
│ │ ├── StackTraceRecoveryNestedTest.kt
│ │ ├── StackTraceRecoveryResumeModeTest.kt
│ │ ├── StackTraceRecoverySelectTest.kt
│ │ ├── StackTraceRecoveryTest.kt
│ │ ├── StackTraceRecoveryWithTimeoutTest.kt
│ │ ├── Stacktraces.kt
│ │ ├── SuppressionTests.kt
│ │ ├── WithContextCancellationStressTest.kt
│ │ └── WithContextExceptionHandlingTest.kt
│ │ ├── flow
│ │ ├── CallbackFlowTest.kt
│ │ ├── ExceptionTransparencyTest.kt
│ │ ├── FirstJvmTest.kt
│ │ ├── FlatMapStressTest.kt
│ │ ├── OnCompletionInterceptedReleaseTest.kt
│ │ ├── SafeCollectorMemoryLeakTest.kt
│ │ ├── SharedFlowStressTest.kt
│ │ ├── SharingReferenceTest.kt
│ │ ├── SharingStressTest.kt
│ │ ├── StateFlowCancellabilityTest.kt
│ │ ├── StateFlowStressTest.kt
│ │ └── StateFlowUpdateStressTest.kt
│ │ ├── guide
│ │ ├── example-basic-01.kt
│ │ ├── example-basic-02.kt
│ │ ├── example-basic-03.kt
│ │ ├── example-basic-04.kt
│ │ ├── example-basic-05.kt
│ │ ├── example-basic-06.kt
│ │ ├── example-cancel-01.kt
│ │ ├── example-cancel-02.kt
│ │ ├── example-cancel-03.kt
│ │ ├── example-cancel-04.kt
│ │ ├── example-cancel-05.kt
│ │ ├── example-cancel-06.kt
│ │ ├── example-cancel-07.kt
│ │ ├── example-cancel-08.kt
│ │ ├── example-cancel-09.kt
│ │ ├── example-cancel-10.kt
│ │ ├── example-channel-01.kt
│ │ ├── example-channel-02.kt
│ │ ├── example-channel-03.kt
│ │ ├── example-channel-04.kt
│ │ ├── example-channel-05.kt
│ │ ├── example-channel-06.kt
│ │ ├── example-channel-07.kt
│ │ ├── example-channel-08.kt
│ │ ├── example-channel-09.kt
│ │ ├── example-channel-10.kt
│ │ ├── example-compose-01.kt
│ │ ├── example-compose-02.kt
│ │ ├── example-compose-03.kt
│ │ ├── example-compose-04.kt
│ │ ├── example-compose-05.kt
│ │ ├── example-compose-06.kt
│ │ ├── example-context-01.kt
│ │ ├── example-context-02.kt
│ │ ├── example-context-03.kt
│ │ ├── example-context-04.kt
│ │ ├── example-context-05.kt
│ │ ├── example-context-06.kt
│ │ ├── example-context-07.kt
│ │ ├── example-context-08.kt
│ │ ├── example-context-09.kt
│ │ ├── example-context-10.kt
│ │ ├── example-context-11.kt
│ │ ├── example-exceptions-01.kt
│ │ ├── example-exceptions-02.kt
│ │ ├── example-exceptions-03.kt
│ │ ├── example-exceptions-04.kt
│ │ ├── example-exceptions-05.kt
│ │ ├── example-exceptions-06.kt
│ │ ├── example-flow-01.kt
│ │ ├── example-flow-02.kt
│ │ ├── example-flow-03.kt
│ │ ├── example-flow-04.kt
│ │ ├── example-flow-05.kt
│ │ ├── example-flow-06.kt
│ │ ├── example-flow-07.kt
│ │ ├── example-flow-08.kt
│ │ ├── example-flow-09.kt
│ │ ├── example-flow-10.kt
│ │ ├── example-flow-11.kt
│ │ ├── example-flow-12.kt
│ │ ├── example-flow-13.kt
│ │ ├── example-flow-14.kt
│ │ ├── example-flow-15.kt
│ │ ├── example-flow-16.kt
│ │ ├── example-flow-17.kt
│ │ ├── example-flow-18.kt
│ │ ├── example-flow-19.kt
│ │ ├── example-flow-20.kt
│ │ ├── example-flow-21.kt
│ │ ├── example-flow-22.kt
│ │ ├── example-flow-23.kt
│ │ ├── example-flow-24.kt
│ │ ├── example-flow-25.kt
│ │ ├── example-flow-26.kt
│ │ ├── example-flow-27.kt
│ │ ├── example-flow-28.kt
│ │ ├── example-flow-29.kt
│ │ ├── example-flow-30.kt
│ │ ├── example-flow-31.kt
│ │ ├── example-flow-32.kt
│ │ ├── example-flow-33.kt
│ │ ├── example-flow-34.kt
│ │ ├── example-flow-35.kt
│ │ ├── example-flow-36.kt
│ │ ├── example-flow-37.kt
│ │ ├── example-flow-38.kt
│ │ ├── example-flow-39.kt
│ │ ├── example-select-01.kt
│ │ ├── example-select-02.kt
│ │ ├── example-select-03.kt
│ │ ├── example-select-04.kt
│ │ ├── example-select-05.kt
│ │ ├── example-supervision-01.kt
│ │ ├── example-supervision-02.kt
│ │ ├── example-supervision-03.kt
│ │ ├── example-sync-01.kt
│ │ ├── example-sync-02.kt
│ │ ├── example-sync-03.kt
│ │ ├── example-sync-04.kt
│ │ ├── example-sync-05.kt
│ │ ├── example-sync-06.kt
│ │ ├── example-sync-07.kt
│ │ └── test
│ │ │ ├── BasicsGuideTest.kt
│ │ │ ├── CancellationGuideTest.kt
│ │ │ ├── ChannelsGuideTest.kt
│ │ │ ├── ComposingGuideTest.kt
│ │ │ ├── DispatcherGuideTest.kt
│ │ │ ├── ExceptionsGuideTest.kt
│ │ │ ├── FlowGuideTest.kt
│ │ │ ├── SelectGuideTest.kt
│ │ │ └── SharedStateGuideTest.kt
│ │ ├── internal
│ │ ├── ConcurrentWeakMapCollectionStressTest.kt
│ │ ├── ConcurrentWeakMapOperationStressTest.kt
│ │ ├── ConcurrentWeakMapTest.kt
│ │ ├── FastServiceLoaderTest.kt
│ │ ├── LockFreeLinkedListLongStressTest.kt
│ │ ├── LockFreeTaskQueueStressTest.kt
│ │ ├── LockFreeTaskQueueTest.kt
│ │ ├── OnDemandAllocatingPoolLincheckTest.kt
│ │ ├── ThreadSafeHeapStressTest.kt
│ │ └── ThreadSafeHeapTest.kt
│ │ ├── jdk8
│ │ ├── future
│ │ │ ├── AsFutureTest.kt
│ │ │ ├── FutureAsDeferredUnhandledCompletionExceptionTest.kt
│ │ │ ├── FutureExceptionsTest.kt
│ │ │ └── FutureTest.kt
│ │ ├── stream
│ │ │ └── ConsumeAsFlowTest.kt
│ │ └── time
│ │ │ ├── DurationOverflowTest.kt
│ │ │ ├── FlowDebounceTest.kt
│ │ │ ├── FlowSampleTest.kt
│ │ │ └── WithTimeoutTest.kt
│ │ ├── knit
│ │ ├── ClosedAfterGuideTestExecutor.kt
│ │ └── TestUtil.kt
│ │ ├── lincheck
│ │ ├── ChannelsLincheckTest.kt
│ │ ├── LockFreeTaskQueueLincheckTest.kt
│ │ ├── MutexLincheckTest.kt
│ │ ├── ResizableAtomicArrayLincheckTest.kt
│ │ └── SemaphoreLincheckTest.kt
│ │ ├── scheduling
│ │ ├── BlockingCoroutineDispatcherLivenessStressTest.kt
│ │ ├── BlockingCoroutineDispatcherMixedStealingStressTest.kt
│ │ ├── BlockingCoroutineDispatcherTerminationStressTest.kt
│ │ ├── BlockingCoroutineDispatcherTest.kt
│ │ ├── BlockingCoroutineDispatcherThreadLimitStressTest.kt
│ │ ├── BlockingCoroutineDispatcherWorkSignallingStressTest.kt
│ │ ├── CoroutineDispatcherTest.kt
│ │ ├── CoroutineSchedulerCloseStressTest.kt
│ │ ├── CoroutineSchedulerInternalApiStressTest.kt
│ │ ├── CoroutineSchedulerLivenessStressTest.kt
│ │ ├── CoroutineSchedulerOversubscriptionTest.kt
│ │ ├── CoroutineSchedulerStressTest.kt
│ │ ├── CoroutineSchedulerTest.kt
│ │ ├── DefaultDispatchersTest.kt
│ │ ├── LimitingCoroutineDispatcherStressTest.kt
│ │ ├── LimitingDispatcherTest.kt
│ │ ├── SchedulerTestBase.kt
│ │ ├── SharingWorkerClassTest.kt
│ │ ├── TestTimeSource.kt
│ │ ├── WorkQueueStressTest.kt
│ │ └── WorkQueueTest.kt
│ │ └── selects
│ │ ├── SelectDeadlockStressTest.kt
│ │ ├── SelectMemoryLeakStressTest.kt
│ │ └── SelectPhilosophersStressTest.kt
├── knit.properties
├── native
│ ├── src
│ │ ├── Builders.kt
│ │ ├── CloseableCoroutineDispatcher.kt
│ │ ├── CoroutineContext.kt
│ │ ├── Debug.kt
│ │ ├── Dispatchers.kt
│ │ ├── EventLoop.kt
│ │ ├── Exceptions.kt
│ │ ├── MultithreadedDispatchers.kt
│ │ ├── Runnable.kt
│ │ ├── SchedulerTask.kt
│ │ ├── flow
│ │ │ └── internal
│ │ │ │ ├── FlowExceptions.kt
│ │ │ │ └── SafeCollector.kt
│ │ └── internal
│ │ │ ├── Concurrent.kt
│ │ │ ├── CopyOnWriteList.kt
│ │ │ ├── CoroutineExceptionHandlerImpl.kt
│ │ │ ├── LocalAtomics.kt
│ │ │ ├── ProbesSupport.kt
│ │ │ ├── StackTraceRecovery.kt
│ │ │ ├── Synchronized.kt
│ │ │ ├── SystemProps.kt
│ │ │ ├── ThreadContext.kt
│ │ │ └── ThreadLocal.kt
│ └── test
│ │ ├── ConcurrentTestUtilities.kt
│ │ ├── DelayExceptionTest.kt
│ │ ├── MultithreadedDispatchersTest.kt
│ │ └── WorkerTest.kt
├── nativeDarwin
│ ├── src
│ │ └── Dispatchers.kt
│ └── test
│ │ ├── Launcher.kt
│ │ └── MainDispatcherTest.kt
├── nativeOther
│ ├── src
│ │ └── Dispatchers.kt
│ └── test
│ │ └── Launcher.kt
├── wasmJs
│ ├── src
│ │ ├── CoroutineContext.kt
│ │ ├── Debug.kt
│ │ ├── JSDispatcher.kt
│ │ ├── Promise.kt
│ │ └── internal
│ │ │ ├── CopyOnWriteList.kt
│ │ │ └── CoroutineExceptionHandlerImpl.kt
│ └── test
│ │ └── PromiseTest.kt
└── wasmWasi
│ └── src
│ ├── Debug.kt
│ ├── EventLoop.kt
│ └── internal
│ ├── CoroutineExceptionHandlerImpl.kt
│ └── CoroutineRunner.kt
├── kotlinx-coroutines-debug
├── README.md
├── api
│ └── kotlinx-coroutines-debug.api
├── build.gradle.kts
├── resources
│ └── META-INF
│ │ └── services
│ │ └── reactor.blockhound.integration.BlockHoundIntegration
├── src
│ ├── Attach.kt
│ ├── CoroutineInfo.kt
│ ├── CoroutinesBlockHoundIntegration.kt
│ ├── DebugProbes.kt
│ ├── NoOpProbes.kt
│ ├── junit
│ │ ├── CoroutinesTimeoutImpl.kt
│ │ ├── junit4
│ │ │ ├── CoroutinesTimeout.kt
│ │ │ └── CoroutinesTimeoutStatement.kt
│ │ └── junit5
│ │ │ ├── CoroutinesTimeout.kt
│ │ │ └── CoroutinesTimeoutExtension.kt
│ └── module-info.java
└── test
│ ├── BlockHoundTest.kt
│ ├── CoroutinesDumpTest.kt
│ ├── DebugLeaksTest.kt
│ ├── DebugProbesTest.kt
│ ├── DebugTestBase.kt
│ ├── DumpCoroutineInfoAsJsonAndReferencesTest.kt
│ ├── DumpWithCreationStackTraceTest.kt
│ ├── EnhanceStackTraceWithTreadDumpAsJsonTest.kt
│ ├── Example.kt
│ ├── LazyCoroutineTest.kt
│ ├── RecoveryExample.kt
│ ├── RunningThreadStackMergeTest.kt
│ ├── SanitizedProbesTest.kt
│ ├── ScopedBuildersTest.kt
│ ├── StacktraceUtils.kt
│ ├── StandardBuildersDebugTest.kt
│ ├── StartModeProbesTest.kt
│ ├── TestRuleExample.kt
│ ├── ToStringTest.kt
│ ├── WithContextUndispatchedTest.kt
│ ├── junit4
│ ├── CoroutinesTimeoutDisabledTracesTest.kt
│ ├── CoroutinesTimeoutEagerTest.kt
│ ├── CoroutinesTimeoutTest.kt
│ └── TestFailureValidation.kt
│ └── junit5
│ ├── CoroutinesTimeoutExtensionTest.kt
│ ├── CoroutinesTimeoutInheritanceTest.kt
│ ├── CoroutinesTimeoutMethodTest.kt
│ ├── CoroutinesTimeoutNestedTest.kt
│ ├── CoroutinesTimeoutSimpleTest.kt
│ ├── CoroutinesTimeoutTest.kt
│ └── RegisterExtensionExample.kt
├── kotlinx-coroutines-test
├── MIGRATION.md
├── README.md
├── api
│ ├── kotlinx-coroutines-test.api
│ └── kotlinx-coroutines-test.klib.api
├── build.gradle.kts
├── common
│ ├── src
│ │ ├── TestBuilders.kt
│ │ ├── TestCoroutineDispatchers.kt
│ │ ├── TestCoroutineScheduler.kt
│ │ ├── TestDispatcher.kt
│ │ ├── TestDispatchers.kt
│ │ ├── TestScope.kt
│ │ └── internal
│ │ │ ├── ExceptionCollector.kt
│ │ │ ├── ReportingSupervisorJob.kt
│ │ │ └── TestMainDispatcher.kt
│ └── test
│ │ ├── Helpers.kt
│ │ ├── RunTestTest.kt
│ │ ├── StandardTestDispatcherTest.kt
│ │ ├── TestCoroutineSchedulerTest.kt
│ │ ├── TestDispatchersTest.kt
│ │ ├── TestScopeTest.kt
│ │ └── UnconfinedTestDispatcherTest.kt
├── js
│ ├── src
│ │ ├── TestBuilders.kt
│ │ └── internal
│ │ │ ├── JsPromiseInterfaceForTesting.kt
│ │ │ └── TestMainDispatcher.kt
│ └── test
│ │ ├── Helpers.kt
│ │ └── PromiseTest.kt
├── jvm
│ ├── resources
│ │ └── META-INF
│ │ │ ├── proguard
│ │ │ └── coroutines.pro
│ │ │ └── services
│ │ │ ├── kotlinx.coroutines.CoroutineExceptionHandler
│ │ │ └── kotlinx.coroutines.internal.MainDispatcherFactory
│ ├── src
│ │ ├── TestBuildersJvm.kt
│ │ ├── internal
│ │ │ └── TestMainDispatcherJvm.kt
│ │ ├── migration
│ │ │ ├── TestBuildersDeprecated.kt
│ │ │ ├── TestCoroutineDispatcher.kt
│ │ │ ├── TestCoroutineExceptionHandler.kt
│ │ │ └── TestCoroutineScope.kt
│ │ └── module-info.java
│ └── test
│ │ ├── DumpOnTimeoutTest.kt
│ │ ├── HelpersJvm.kt
│ │ ├── MemoryLeakTest.kt
│ │ ├── MultithreadingTest.kt
│ │ ├── RunTestStressTest.kt
│ │ ├── UncaughtExceptionsTest.kt
│ │ └── migration
│ │ ├── RunBlockingTestOnTestScopeTest.kt
│ │ ├── RunTestLegacyScopeTest.kt
│ │ ├── TestBuildersTest.kt
│ │ ├── TestCoroutineDispatcherTest.kt
│ │ ├── TestCoroutineScopeTest.kt
│ │ ├── TestRunBlockingOrderTest.kt
│ │ └── TestRunBlockingTest.kt
├── native
│ ├── src
│ │ ├── TestBuilders.kt
│ │ └── internal
│ │ │ └── TestMainDispatcher.kt
│ └── test
│ │ └── Helpers.kt
├── npm
│ ├── README.md
│ └── package.json
├── wasmJs
│ ├── src
│ │ ├── TestBuilders.kt
│ │ └── internal
│ │ │ ├── JsPromiseInterfaceForTesting.kt
│ │ │ └── TestMainDispatcher.kt
│ └── test
│ │ ├── Helpers.kt
│ │ └── PromiseTest.kt
└── wasmWasi
│ ├── src
│ ├── TestBuilders.kt
│ └── internal
│ │ └── TestMainDispatcher.kt
│ └── test
│ └── Helpers.kt
├── license
└── NOTICE.txt
├── reactive
├── README.md
├── knit.properties
├── knit.test.include
├── kotlinx-coroutines-jdk9
│ ├── README.md
│ ├── api
│ │ └── kotlinx-coroutines-jdk9.api
│ ├── build.gradle.kts
│ ├── package.list
│ ├── src
│ │ ├── Await.kt
│ │ ├── Publish.kt
│ │ ├── ReactiveFlow.kt
│ │ └── module-info.java
│ └── test
│ │ ├── AwaitTest.kt
│ │ ├── FlowAsPublisherTest.kt
│ │ ├── IntegrationTest.kt
│ │ ├── PublishTest.kt
│ │ ├── PublisherAsFlowTest.kt
│ │ ├── PublisherBackpressureTest.kt
│ │ ├── PublisherCollectTest.kt
│ │ ├── PublisherCompletionStressTest.kt
│ │ └── PublisherMultiTest.kt
├── kotlinx-coroutines-reactive
│ ├── README.md
│ ├── api
│ │ └── kotlinx-coroutines-reactive.api
│ ├── build.gradle.kts
│ ├── package.list
│ ├── src
│ │ ├── Await.kt
│ │ ├── Channel.kt
│ │ ├── ContextInjector.kt
│ │ ├── Convert.kt
│ │ ├── Migration.kt
│ │ ├── Publish.kt
│ │ ├── ReactiveFlow.kt
│ │ └── module-info.java
│ └── test
│ │ ├── AwaitCancellationStressTest.kt
│ │ ├── AwaitTest.kt
│ │ ├── CancelledParentAttachTest.kt
│ │ ├── FlowAsPublisherTest.kt
│ │ ├── IntegrationTest.kt
│ │ ├── IterableFlowTckTest.kt
│ │ ├── PublishTest.kt
│ │ ├── PublisherAsFlowTest.kt
│ │ ├── PublisherBackpressureTest.kt
│ │ ├── PublisherCollectTest.kt
│ │ ├── PublisherCompletionStressTest.kt
│ │ ├── PublisherMultiTest.kt
│ │ ├── PublisherRequestStressTest.kt
│ │ ├── PublisherSubscriptionSelectTest.kt
│ │ ├── RangePublisherBufferedTest.kt
│ │ ├── RangePublisherTest.kt
│ │ ├── ReactiveStreamTckTest.kt
│ │ └── UnboundedIntegerIncrementPublisherTest.kt
├── kotlinx-coroutines-reactor
│ ├── README.md
│ ├── api
│ │ └── kotlinx-coroutines-reactor.api
│ ├── build.gradle.kts
│ ├── package.list
│ ├── resources
│ │ └── META-INF
│ │ │ └── services
│ │ │ └── kotlinx.coroutines.reactive.ContextInjector
│ ├── src
│ │ ├── Convert.kt
│ │ ├── Flux.kt
│ │ ├── Migration.kt
│ │ ├── Mono.kt
│ │ ├── ReactorContext.kt
│ │ ├── ReactorContextInjector.kt
│ │ ├── ReactorFlow.kt
│ │ ├── Scheduler.kt
│ │ └── module-info.java
│ └── test
│ │ ├── BackpressureTest.kt
│ │ ├── Check.kt
│ │ ├── ConvertTest.kt
│ │ ├── FlowAsFluxTest.kt
│ │ ├── FluxCompletionStressTest.kt
│ │ ├── FluxContextTest.kt
│ │ ├── FluxMultiTest.kt
│ │ ├── FluxSingleTest.kt
│ │ ├── FluxTest.kt
│ │ ├── MonoAwaitStressTest.kt
│ │ ├── MonoTest.kt
│ │ ├── ReactorContextTest.kt
│ │ └── SchedulerTest.kt
├── kotlinx-coroutines-rx2
│ ├── README.md
│ ├── api
│ │ └── kotlinx-coroutines-rx2.api
│ ├── build.gradle.kts
│ ├── package.list
│ ├── src
│ │ ├── RxAwait.kt
│ │ ├── RxCancellable.kt
│ │ ├── RxChannel.kt
│ │ ├── RxCompletable.kt
│ │ ├── RxConvert.kt
│ │ ├── RxFlowable.kt
│ │ ├── RxMaybe.kt
│ │ ├── RxObservable.kt
│ │ ├── RxScheduler.kt
│ │ ├── RxSingle.kt
│ │ └── module-info.java
│ └── test
│ │ ├── BackpressureTest.kt
│ │ ├── Check.kt
│ │ ├── CompletableTest.kt
│ │ ├── ConvertTest.kt
│ │ ├── FlowAsFlowableTest.kt
│ │ ├── FlowAsObservableTest.kt
│ │ ├── FlowableContextTest.kt
│ │ ├── FlowableExceptionHandlingTest.kt
│ │ ├── FlowableTest.kt
│ │ ├── IntegrationTest.kt
│ │ ├── IterableFlowAsFlowableTckTest.kt
│ │ ├── LeakedExceptionTest.kt
│ │ ├── MaybeTest.kt
│ │ ├── ObservableAsFlowTest.kt
│ │ ├── ObservableCollectTest.kt
│ │ ├── ObservableCompletionStressTest.kt
│ │ ├── ObservableExceptionHandlingTest.kt
│ │ ├── ObservableMultiTest.kt
│ │ ├── ObservableSingleTest.kt
│ │ ├── ObservableSourceAsFlowStressTest.kt
│ │ ├── ObservableSubscriptionSelectTest.kt
│ │ ├── ObservableTest.kt
│ │ ├── SchedulerStressTest.kt
│ │ ├── SchedulerTest.kt
│ │ └── SingleTest.kt
└── kotlinx-coroutines-rx3
│ ├── README.md
│ ├── api
│ └── kotlinx-coroutines-rx3.api
│ ├── build.gradle.kts
│ ├── package.list
│ ├── src
│ ├── RxAwait.kt
│ ├── RxCancellable.kt
│ ├── RxChannel.kt
│ ├── RxCompletable.kt
│ ├── RxConvert.kt
│ ├── RxFlowable.kt
│ ├── RxMaybe.kt
│ ├── RxObservable.kt
│ ├── RxScheduler.kt
│ ├── RxSingle.kt
│ └── module-info.java
│ └── test
│ ├── BackpressureTest.kt
│ ├── Check.kt
│ ├── CompletableTest.kt
│ ├── ConvertTest.kt
│ ├── FlowAsFlowableTest.kt
│ ├── FlowAsObservableTest.kt
│ ├── FlowableContextTest.kt
│ ├── FlowableExceptionHandlingTest.kt
│ ├── FlowableTest.kt
│ ├── IntegrationTest.kt
│ ├── IterableFlowAsFlowableTckTest.kt
│ ├── LeakedExceptionTest.kt
│ ├── MaybeTest.kt
│ ├── ObservableAsFlowTest.kt
│ ├── ObservableCollectTest.kt
│ ├── ObservableCompletionStressTest.kt
│ ├── ObservableExceptionHandlingTest.kt
│ ├── ObservableMultiTest.kt
│ ├── ObservableSingleTest.kt
│ ├── ObservableSourceAsFlowStressTest.kt
│ ├── ObservableSubscriptionSelectTest.kt
│ ├── ObservableTest.kt
│ ├── SchedulerStressTest.kt
│ ├── SchedulerTest.kt
│ └── SingleTest.kt
├── settings.gradle.kts
├── site
└── stdlib.package.list
├── test-utils
├── build.gradle.kts
├── common
│ └── src
│ │ ├── LaunchFlow.kt
│ │ ├── MainDispatcherTestBase.kt
│ │ └── TestBase.common.kt
├── js
│ └── src
│ │ └── TestBase.kt
├── jvm
│ └── src
│ │ ├── Exceptions.kt
│ │ ├── ExecutorRule.kt
│ │ ├── FieldWalker.kt
│ │ ├── TestBase.kt
│ │ └── Threads.kt
├── native
│ └── src
│ │ └── TestBase.kt
├── wasmJs
│ └── src
│ │ └── TestBase.kt
└── wasmWasi
│ └── src
│ └── TestBase.kt
└── ui
├── README.md
├── coroutines-guide-ui.md
├── knit.code.include
├── knit.properties
├── kotlinx-coroutines-android
├── README.md
├── android-unit-tests
│ ├── build.gradle.kts
│ ├── resources
│ │ └── META-INF
│ │ │ └── services
│ │ │ └── kotlinx.coroutines.CoroutineScope
│ ├── src
│ │ └── EmptyCoroutineScopeImpl.kt
│ └── test
│ │ └── ordered
│ │ └── tests
│ │ ├── CustomizedRobolectricTest.kt
│ │ ├── FirstMockedMainTest.kt
│ │ ├── FirstRobolectricTest.kt
│ │ ├── MockedMainTest.kt
│ │ ├── RobolectricTest.kt
│ │ └── TestComponent.kt
├── api
│ └── kotlinx-coroutines-android.api
├── build.gradle.kts
├── package.list
├── resources
│ └── META-INF
│ │ ├── com.android.tools
│ │ ├── proguard
│ │ │ └── coroutines.pro
│ │ ├── r8-from-1.6.0
│ │ │ └── coroutines.pro
│ │ └── r8-upto-3.0.0
│ │ │ └── coroutines.pro
│ │ ├── proguard
│ │ └── coroutines.pro
│ │ └── services
│ │ ├── kotlinx.coroutines.CoroutineExceptionHandler
│ │ └── kotlinx.coroutines.internal.MainDispatcherFactory
├── src
│ ├── AndroidExceptionPreHandler.kt
│ ├── HandlerDispatcher.kt
│ └── module-info.java
├── test
│ ├── AndroidExceptionPreHandlerTest.kt
│ ├── DisabledHandlerTest.kt
│ ├── HandlerDispatcherAsyncTest.kt
│ ├── HandlerDispatcherTest.kt
│ └── R8ServiceLoaderOptimizationTest.kt
└── testdata
│ ├── r8-test-common.pro
│ ├── r8-test-rules-no-optim.pro
│ └── r8-test-rules.pro
├── kotlinx-coroutines-javafx
├── README.md
├── api
│ └── kotlinx-coroutines-javafx.api
├── build.gradle.kts
├── resources
│ └── META-INF
│ │ └── services
│ │ └── kotlinx.coroutines.internal.MainDispatcherFactory
├── src
│ ├── JavaFxConvert.kt
│ ├── JavaFxDispatcher.kt
│ └── module-info.java
└── test
│ ├── JavaFxDispatcherTest.kt
│ ├── JavaFxObservableAsFlowTest.kt
│ ├── JavaFxStressTest.kt
│ ├── examples
│ ├── FxAsFlow.kt
│ └── FxExampleApp.kt
│ └── guide
│ ├── example-ui-actor-01.kt
│ ├── example-ui-actor-02.kt
│ ├── example-ui-actor-03.kt
│ ├── example-ui-advanced-01.kt
│ ├── example-ui-advanced-02.kt
│ ├── example-ui-basic-01.kt
│ ├── example-ui-basic-02.kt
│ ├── example-ui-basic-03.kt
│ ├── example-ui-blocking-01.kt
│ ├── example-ui-blocking-02.kt
│ └── example-ui-blocking-03.kt
├── kotlinx-coroutines-swing
├── README.md
├── api
│ └── kotlinx-coroutines-swing.api
├── build.gradle.kts
├── resources
│ └── META-INF
│ │ └── services
│ │ └── kotlinx.coroutines.internal.MainDispatcherFactory
├── src
│ ├── SwingDispatcher.kt
│ └── module-info.java
└── test
│ ├── SwingTest.kt
│ └── examples
│ └── SwingExampleApp.kt
├── ui-example-android.png
└── ui-example-javafx.png
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | blank_issues_enabled: true
2 | contact_links:
3 | - name: Kotlinlang Slack
4 | url: https://surveys.jetbrains.com/s3/kotlin-slack-sign-up
5 | about: Please ask and answer usage-related questions here.
6 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/guide.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Issue with the Coroutines guide
3 | about: Problems on https://kotlinlang.org/docs/coroutines-guide.html
4 | title: ''
5 | labels: guide
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Which page?**
11 |
12 | Drop a link to a specific page, unless you're reporting something that's missing entirely.
13 |
14 | **What can be improved?**
15 |
16 | Describe the problematic part. Is it misleading, unclear, or just something that didn’t work for you?
17 |
18 | **Is this explained better somewhere else?**
19 |
20 | Show us the explanation that made it click for you.
21 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | **/.idea/*
2 | !/.idea/icon.png
3 | !/.idea/vcs.xml
4 | !/.idea/copyright
5 | !/.idea/codeStyleSettings.xml
6 | !/.idea/codeStyles
7 | !/.idea/dictionaries
8 | *.iml
9 | .gradle
10 | .gradletasknamecache
11 | build
12 | out
13 | target
14 | local.properties
15 | benchmarks.jar
16 | /kotlin-js-store
17 | /.kotlin
18 |
--------------------------------------------------------------------------------
/.idea/codeStyleSettings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/dictionaries/shared.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Alistarh
5 | Elizarov
6 | Koval
7 | kotlinx
8 | lincheck
9 | linearizability
10 | linearizable
11 | redirector
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/.idea/icon.png
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | ## Code of Conduct
2 |
3 | This project and the corresponding community is governed by the [JetBrains Open Source and Community Code of Conduct](https://confluence.jetbrains.com/display/ALL/JetBrains+Open+Source+and+Community+Code+of+Conduct). Please make sure you read it.
4 |
5 |
--------------------------------------------------------------------------------
/benchmarks/src/jmh/kotlin/benchmarks/flow/scrabble/IterableSpliterator.kt:
--------------------------------------------------------------------------------
1 | package benchmarks.flow.scrabble
2 |
3 | import java.util.*
4 |
5 | object IterableSpliterator {
6 | @JvmStatic
7 | public fun of(spliterator: Spliterator): Iterable = Iterable { Spliterators.iterator(spliterator) }
8 | }
9 |
--------------------------------------------------------------------------------
/benchmarks/src/jmh/resources/ospd.txt.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/benchmarks/src/jmh/resources/ospd.txt.gz
--------------------------------------------------------------------------------
/benchmarks/src/jmh/resources/words.shakespeare.txt.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/benchmarks/src/jmh/resources/words.shakespeare.txt.gz
--------------------------------------------------------------------------------
/benchmarks/src/main/kotlin/benchmarks/common/BenchmarkUtils.kt:
--------------------------------------------------------------------------------
1 | package benchmarks.common
2 |
3 | import java.util.concurrent.*
4 |
5 | public fun doGeomDistrWork(work: Int) {
6 | // We use geometric distribution here. We also checked on macbook pro 13" (2017) that the resulting work times
7 | // are distributed geometrically, see https://github.com/Kotlin/kotlinx.coroutines/pull/1464#discussion_r355705325
8 | val p = 1.0 / work
9 | val r = ThreadLocalRandom.current()
10 | while (true) {
11 | if (r.nextDouble() < p) break
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/buildSrc/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | val build_snapshot_train: String? by settings
3 | repositories {
4 | val cacheRedirectorEnabled = System.getenv("CACHE_REDIRECTOR")?.toBoolean() == true
5 | if (cacheRedirectorEnabled) {
6 | println("Redirecting repositories for buildSrc buildscript")
7 | maven("https://cache-redirector.jetbrains.com/plugins.gradle.org/m2")
8 | } else {
9 | maven("https://plugins.gradle.org/m2")
10 | }
11 | if (build_snapshot_train?.toBoolean() == true) {
12 | mavenLocal()
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/buildSrc/src/main/kotlin/Dokka.kt:
--------------------------------------------------------------------------------
1 | import org.gradle.api.*
2 | import org.gradle.kotlin.dsl.*
3 | import org.jetbrains.dokka.gradle.*
4 | import java.io.*
5 | import java.net.*
6 |
7 | /**
8 | * Package-list by external URL for documentation generation.
9 | */
10 | fun Project.externalDocumentationLink(
11 | url: String,
12 | packageList: File = projectDir.resolve("package.list")
13 | ) {
14 | tasks.withType().configureEach {
15 | dokkaSourceSets.configureEach {
16 | externalDocumentationLink {
17 | this.url = URL(url)
18 | packageListUrl = packageList.toPath().toUri().toURL()
19 | }
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/buildSrc/src/main/kotlin/GlobalKotlinCompilerOptions.kt:
--------------------------------------------------------------------------------
1 | import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
2 |
3 | internal fun KotlinCommonCompilerOptions.configureGlobalKotlinArgumentsAndOptIns() {
4 | freeCompilerArgs.addAll("-progressive")
5 | optIn.addAll(
6 | "kotlin.experimental.ExperimentalTypeInference",
7 | // our own opt-ins that we don't want to bother with in our own code:
8 | "kotlinx.coroutines.DelicateCoroutinesApi",
9 | "kotlinx.coroutines.ExperimentalCoroutinesApi",
10 | "kotlinx.coroutines.ObsoleteCoroutinesApi",
11 | "kotlinx.coroutines.InternalCoroutinesApi",
12 | "kotlinx.coroutines.FlowPreview"
13 | )
14 | }
15 |
--------------------------------------------------------------------------------
/buildSrc/src/main/kotlin/Idea.kt:
--------------------------------------------------------------------------------
1 | object Idea {
2 | @JvmStatic // for Gradle
3 | val active: Boolean
4 | get() = System.getProperty("idea.active") == "true"
5 | }
6 |
--------------------------------------------------------------------------------
/buildSrc/src/main/kotlin/Platform.kt:
--------------------------------------------------------------------------------
1 | import org.gradle.api.Project
2 |
3 | // Use from Groovy for now
4 | fun platformOf(project: Project): String =
5 | when (project.name.substringAfterLast("-")) {
6 | "js" -> "js"
7 | "common", "native" -> throw IllegalStateException("${project.name} platform is not supported")
8 | else -> "jvm"
9 | }
10 |
--------------------------------------------------------------------------------
/buildSrc/src/main/kotlin/animalsniffer-jvm-conventions.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("ru.vyarus.animalsniffer")
3 | }
4 |
5 | project.plugins.withType(JavaPlugin::class.java) {
6 | val signature: Configuration by configurations
7 | dependencies {
8 | signature("net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature")
9 | signature("org.codehaus.mojo.signature:java17:1.0@signature")
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/buildSrc/src/main/kotlin/animalsniffer-multiplatform-conventions.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("ru.vyarus.animalsniffer")
3 | }
4 |
5 | project.plugins.withType(KotlinMultiplatformConventionsPlugin::class.java) {
6 | val signature: Configuration by configurations
7 | dependencies {
8 | signature("net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature")
9 | signature("org.codehaus.mojo.signature:java17:1.0@signature")
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/buildSrc/src/main/kotlin/bom-conventions.gradle.kts:
--------------------------------------------------------------------------------
1 | import org.gradle.kotlin.dsl.*
2 | import org.jetbrains.kotlin.gradle.dsl.*
3 |
4 |
5 | configure(subprojects.filter { it.name !in unpublished }) {
6 | if (name == "kotlinx-coroutines-bom" || name == "kotlinx.coroutines") return@configure
7 | if (isMultiplatform) {
8 | kotlinExtension.sourceSets.getByName("jvmMain").dependencies {
9 | api(project.dependencies.platform(project(":kotlinx-coroutines-bom")))
10 | }
11 | } else {
12 | dependencies {
13 | "api"(platform(project(":kotlinx-coroutines-bom")))
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/buildSrc/src/main/kotlin/java-modularity-conventions.gradle.kts:
--------------------------------------------------------------------------------
1 | // Currently the compilation of the module-info fails for
2 | // kotlinx-coroutines-play-services because it depends on Android JAR's
3 | // which do not have an explicit module-info descriptor.
4 | // Because the JAR's are all named `classes.jar`,
5 | // the automatic module name also becomes `classes`.
6 | // This conflicts since there are multiple JAR's with identical names.
7 | val invalidModules = listOf("kotlinx-coroutines-play-services")
8 |
9 | configure(subprojects.filter {
10 | !unpublished.contains(it.name) && !invalidModules.contains(it.name) && it.extensions.findByName("kotlin") != null
11 | }) {
12 | Java9Modularity.configure(project)
13 | }
14 |
--------------------------------------------------------------------------------
/buildSrc/src/main/kotlin/knit-conventions.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("kotlinx-knit")
3 | }
4 |
5 | knit {
6 | siteRoot = "https://kotlinlang.org/api/kotlinx.coroutines"
7 | moduleRoots = listOf(".", "integration", "reactive", "ui")
8 | moduleDocs = "build/dokka/htmlPartial"
9 | dokkaMultiModuleRoot = "build/dokka/htmlMultiModule/"
10 | }
11 |
12 | tasks.named("knitPrepare").configure {
13 | val knitTask = this
14 | // In order for knit to operate, it should depend on and collect
15 | // all Dokka outputs from each module
16 | allprojects {
17 | val dokkaTasks = tasks.matching { it.name == "dokkaHtmlMultiModule" }
18 | knitTask.dependsOn(dokkaTasks)
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/buildSrc/src/main/kotlin/source-set-conventions.gradle.kts:
--------------------------------------------------------------------------------
1 | import org.jetbrains.kotlin.gradle.dsl.*
2 |
3 | // Redefine source sets because we are not using 'kotlin/main/fqn' folder convention
4 | // TODO: port benchmarks to the same scheme
5 | configure(subprojects.filter { !sourceless.contains(it.name) && it.name != "benchmarks" }) {
6 | kotlinExtension.sourceSets.forEach {
7 | it.configureDirectoryPaths()
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/buildSrc/src/main/kotlin/version-file-conventions.gradle.kts:
--------------------------------------------------------------------------------
1 | import org.gradle.api.tasks.bundling.*
2 |
3 | configure(subprojects.filter { !unpublished.contains(it.name) && it.name !in sourceless }) {
4 | val project = this
5 | val jarTaskName = when {
6 | isMultiplatform -> "jvmJar"
7 | else -> "jar"
8 | }
9 | val versionFileTask = VersionFile.registerVersionFileTask(project)
10 | tasks.withType(Jar::class.java).named(jarTaskName) {
11 | VersionFile.fromVersionFile(this, versionFileTask)
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/coroutines-guide.md:
--------------------------------------------------------------------------------
1 | The main coroutines guide has moved to the [docs folder](docs/topics/coroutines-guide.md) and split up into smaller documents.
2 |
3 | It is recommended to read the guide on the [kotlinlang website](https://kotlinlang.org/docs/coroutines-guide.html), with proper HTML formatting and runnable samples.
4 |
--------------------------------------------------------------------------------
/docs/basics.md:
--------------------------------------------------------------------------------
1 | The documentation has been moved to the [https://kotlinlang.org/docs/coroutines-basics.html](https://kotlinlang.org/docs/coroutines-basics.html) page.
2 |
3 | To edit the documentation, open the [topics/coroutines-basics.md](topics/coroutines-basics.md) page.
4 |
--------------------------------------------------------------------------------
/docs/cancellation-and-timeouts.md:
--------------------------------------------------------------------------------
1 | The documentation has been moved to the [https://kotlinlang.org/docs/cancellation-and-timeouts.html](https://kotlinlang.org/docs/cancellation-and-timeouts.html) page.
2 |
3 | To edit the documentation, open the [topics/cancellation-and-timeouts.md](topics/cancellation-and-timeouts.md) page.
--------------------------------------------------------------------------------
/docs/cfg/buildprofiles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | true
5 | https://github.com/Kotlin/kotlinx.coroutines/edit/master/docs/
6 | true
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/channels.md:
--------------------------------------------------------------------------------
1 | The documentation has been moved to the [https://kotlinlang.org/docs/channels.html](https://kotlinlang.org/docs/channels.html) page.
2 |
3 | To edit the documentation, open the [topics/channels.md](topics/channels.md) page.
--------------------------------------------------------------------------------
/docs/compatibility.md:
--------------------------------------------------------------------------------
1 | The documentation has been moved to the [topics/compatibility.md](topics/compatibility.md).
--------------------------------------------------------------------------------
/docs/composing-suspending-functions.md:
--------------------------------------------------------------------------------
1 | The documentation has been moved to the [https://kotlinlang.org/docs/composing-suspending-functions.html](https://kotlinlang.org/docs/composing-suspending-functions.html) page.
2 |
3 | To edit the documentation, open the [topics/composing-suspending-functions.md](topics/composing-suspending-functions.md) page.
--------------------------------------------------------------------------------
/docs/coroutine-context-and-dispatchers.md:
--------------------------------------------------------------------------------
1 | The documentation has been moved to the [https://kotlinlang.org/docs/coroutine-context-and-dispatchers.html](https://kotlinlang.org/docs/coroutine-context-and-dispatchers.html) page.
2 |
3 | To edit the documentation, open the [topics/coroutine-context-and-dispatchers.md](topics/coroutine-context-and-dispatchers.md) page.
--------------------------------------------------------------------------------
/docs/coroutines-guide.md:
--------------------------------------------------------------------------------
1 | The documentation has been moved to the [https://kotlinlang.org/docs/coroutines-guide.html](https://kotlinlang.org/docs/coroutines-guide.html) page.
2 |
3 | To edit the documentation, open the [topics/coroutines-guide.md](topics/coroutines-guide.md) page.
--------------------------------------------------------------------------------
/docs/debugging.md:
--------------------------------------------------------------------------------
1 | The documentation has been moved to the [topics/debugging.md](topics/debugging.md).
--------------------------------------------------------------------------------
/docs/exception-handling.md:
--------------------------------------------------------------------------------
1 | The documentation has been moved to the [https://kotlinlang.org/docs/exception-handling.html](https://kotlinlang.org/docs/exception-handling.html) page.
2 |
3 | To edit the documentation, open the [topics/exception-handling.md](topics/exception-handling.md) page.
--------------------------------------------------------------------------------
/docs/flow.md:
--------------------------------------------------------------------------------
1 | The documentation has been moved to the [https://kotlinlang.org/docs/flow.html](https://kotlinlang.org/docs/flow.html) page.
2 |
3 | To edit the documentation, open the [topics/flow.md](topics/flow.md) page.
--------------------------------------------------------------------------------
/docs/images/after.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/after.png
--------------------------------------------------------------------------------
/docs/images/before.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/before.png
--------------------------------------------------------------------------------
/docs/images/coroutine-breakpoint.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/coroutine-breakpoint.png
--------------------------------------------------------------------------------
/docs/images/coroutine-debug-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/coroutine-debug-1.png
--------------------------------------------------------------------------------
/docs/images/coroutine-debug-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/coroutine-debug-2.png
--------------------------------------------------------------------------------
/docs/images/coroutine-debug-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/coroutine-debug-3.png
--------------------------------------------------------------------------------
/docs/images/coroutine-idea-debugging-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/coroutine-idea-debugging-1.png
--------------------------------------------------------------------------------
/docs/images/coroutines-and-channels/aggregate.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/coroutines-and-channels/aggregate.png
--------------------------------------------------------------------------------
/docs/images/coroutines-and-channels/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/coroutines-and-channels/background.png
--------------------------------------------------------------------------------
/docs/images/coroutines-and-channels/blocking.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/coroutines-and-channels/blocking.png
--------------------------------------------------------------------------------
/docs/images/coroutines-and-channels/buffered-channel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/coroutines-and-channels/buffered-channel.png
--------------------------------------------------------------------------------
/docs/images/coroutines-and-channels/callbacks.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/coroutines-and-channels/callbacks.png
--------------------------------------------------------------------------------
/docs/images/coroutines-and-channels/concurrency.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/coroutines-and-channels/concurrency.png
--------------------------------------------------------------------------------
/docs/images/coroutines-and-channels/conflated-channel.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/coroutines-and-channels/conflated-channel.gif
--------------------------------------------------------------------------------
/docs/images/coroutines-and-channels/generating-token.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/coroutines-and-channels/generating-token.png
--------------------------------------------------------------------------------
/docs/images/coroutines-and-channels/initial-window.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/coroutines-and-channels/initial-window.png
--------------------------------------------------------------------------------
/docs/images/coroutines-and-channels/loading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/coroutines-and-channels/loading.gif
--------------------------------------------------------------------------------
/docs/images/coroutines-and-channels/progress-and-concurrency.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/coroutines-and-channels/progress-and-concurrency.png
--------------------------------------------------------------------------------
/docs/images/coroutines-and-channels/progress.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/coroutines-and-channels/progress.png
--------------------------------------------------------------------------------
/docs/images/coroutines-and-channels/rendezvous-channel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/coroutines-and-channels/rendezvous-channel.png
--------------------------------------------------------------------------------
/docs/images/coroutines-and-channels/run-configuration.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/coroutines-and-channels/run-configuration.png
--------------------------------------------------------------------------------
/docs/images/coroutines-and-channels/suspend-requests.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/coroutines-and-channels/suspend-requests.png
--------------------------------------------------------------------------------
/docs/images/coroutines-and-channels/suspension-process.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/coroutines-and-channels/suspension-process.gif
--------------------------------------------------------------------------------
/docs/images/coroutines-and-channels/time-comparison.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/coroutines-and-channels/time-comparison.png
--------------------------------------------------------------------------------
/docs/images/coroutines-and-channels/unlimited-channel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/coroutines-and-channels/unlimited-channel.png
--------------------------------------------------------------------------------
/docs/images/coroutines-and-channels/using-channel-many-coroutines.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/coroutines-and-channels/using-channel-many-coroutines.png
--------------------------------------------------------------------------------
/docs/images/coroutines-and-channels/using-channel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/coroutines-and-channels/using-channel.png
--------------------------------------------------------------------------------
/docs/images/flow-breakpoint.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/flow-breakpoint.png
--------------------------------------------------------------------------------
/docs/images/flow-build-project.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/flow-build-project.png
--------------------------------------------------------------------------------
/docs/images/flow-debug-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/flow-debug-1.png
--------------------------------------------------------------------------------
/docs/images/flow-debug-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/flow-debug-2.png
--------------------------------------------------------------------------------
/docs/images/flow-debug-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/flow-debug-3.png
--------------------------------------------------------------------------------
/docs/images/flow-debug-4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/flow-debug-4.png
--------------------------------------------------------------------------------
/docs/images/flow-debug-project.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/flow-debug-project.png
--------------------------------------------------------------------------------
/docs/images/flow-resume-debug.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/flow-resume-debug.png
--------------------------------------------------------------------------------
/docs/images/new-gradle-project-jvm.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/new-gradle-project-jvm.png
--------------------------------------------------------------------------------
/docs/images/variable-optimised-out.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/docs/images/variable-optimised-out.png
--------------------------------------------------------------------------------
/docs/knit.code.include:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from ${file.name} by Knit tool. Do not edit.
2 | package ${knit.package}.${knit.name}
--------------------------------------------------------------------------------
/docs/knit.test.template:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from ${file.name} by Knit tool. Do not edit.
2 | package ${test.package}
3 |
4 | import kotlinx.coroutines.knit.*
5 | import org.junit.Test
6 |
7 | class ${test.name} {
8 | <#list cases as case><#assign method = test["mode.${case.param}"]!"custom">
9 | @Test
10 | fun test${case.name}() {
11 | test("${case.name}") { ${case.knit.package}.${case.knit.name}.main() }<#if method != "custom">.${method}(
12 | <#list case.lines as line>
13 | "${line?j_string}"<#sep>,#sep>
14 | #list>
15 | )
16 | <#else>.also { lines ->
17 | check(${case.param})
18 | }
19 | #if>
20 | }
21 | <#sep>
22 |
23 | #list>
24 | }
--------------------------------------------------------------------------------
/docs/select-expression.md:
--------------------------------------------------------------------------------
1 | The documentation has been moved to the [https://kotlinlang.org/docs/select-expression.html](https://kotlinlang.org/docs/select-expression.html) page.
2 |
3 | To edit the documentation, open the [topics/select-expression.md](topics/select-expression.md) page.
--------------------------------------------------------------------------------
/docs/shared-mutable-state-and-concurrency.md:
--------------------------------------------------------------------------------
1 | The documentation has been moved to the [https://kotlinlang.org/docs/shared-mutable-state-and-concurrency.html](https://kotlinlang.org/docs/shared-mutable-state-and-concurrency.html) page.
2 |
3 | To edit the documentation, open the [topics/shared-mutable-state-and-concurrency.md](topics/shared-mutable-state-and-concurrency.md) page.
--------------------------------------------------------------------------------
/docs/topics/knit.properties:
--------------------------------------------------------------------------------
1 | knit.package=kotlinx.coroutines.guide
2 | knit.dir=../../kotlinx-coroutines-core/jvm/test/guide/
3 |
4 | test.package=kotlinx.coroutines.guide.test
5 | test.dir=../../kotlinx-coroutines-core/jvm/test/guide/test/
6 |
--------------------------------------------------------------------------------
/docs/writerside.cfg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/dokka-templates/README.md:
--------------------------------------------------------------------------------
1 | # Customize Dokka's HTML.
2 | To customize Dokka's HTML output, place a file in this folder.
3 | Dokka will find a template file there. If the file is not found, a default one will be used.
4 | This folder is defined by the templatesDir property.
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionSha256Sum=fba8464465835e74f7270bbf43d6d8a8d7709ab0a43ce1aa3323f73e9aa0c612
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-all.zip
5 | networkTimeout=10000
6 | validateDistributionUrl=true
7 | zipStoreBase=GRADLE_USER_HOME
8 | zipStorePath=wrapper/dists
9 |
--------------------------------------------------------------------------------
/integration-testing/.gitignore:
--------------------------------------------------------------------------------
1 | .kotlin
2 | kotlin-js-store
--------------------------------------------------------------------------------
/integration-testing/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin_version=2.1.0
2 | coroutines_version=1.10.2-SNAPSHOT
3 | asm_version=9.3
4 | junit5_version=5.7.0
5 |
6 | kotlin.code.style=official
7 | kotlin.mpp.stability.nowarn=true
8 |
--------------------------------------------------------------------------------
/integration-testing/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/integration-testing/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/integration-testing/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip
4 | networkTimeout=10000
5 | validateDistributionUrl=true
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/integration-testing/java8Test/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm")
3 | }
4 |
5 | repositories {
6 | mavenCentral()
7 | maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
8 | // Coroutines from the outer project are published by previous CI buils step
9 | mavenLocal()
10 | }
11 |
12 | tasks.test {
13 | useJUnitPlatform()
14 | }
15 |
16 | val coroutinesVersion = property("coroutines_version")
17 | val junit5Version = property("junit5_version")
18 |
19 | kotlin {
20 | jvmToolchain(8)
21 | dependencies {
22 | implementation("org.jetbrains.kotlinx:kotlinx-coroutines-debug:$coroutinesVersion")
23 | testImplementation("org.junit.jupiter:junit-jupiter-engine:$junit5Version")
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/integration-testing/java8Test/src/test/kotlin/JUnit5TimeoutCompilation.kt:
--------------------------------------------------------------------------------
1 | import kotlinx.coroutines.debug.junit5.CoroutinesTimeout
2 | import org.junit.jupiter.api.*
3 |
4 | class JUnit5TimeoutCompilation {
5 | @CoroutinesTimeout(1000)
6 | @Test
7 | fun testCoroutinesTimeoutNotFailing() {
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/integration-testing/jpmsTest/src/debugDynamicAgentJpmsTest/java/module-info.java:
--------------------------------------------------------------------------------
1 | module debug.dynamic.agent.jpms.test {
2 | requires kotlin.stdlib;
3 | requires kotlinx.coroutines.core;
4 | requires kotlinx.coroutines.debug;
5 | requires junit;
6 | requires kotlin.test;
7 | }
--------------------------------------------------------------------------------
/integration-testing/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | mavenCentral()
4 | maven("https://plugins.gradle.org/m2/")
5 | maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
6 | mavenLocal()
7 | }
8 | }
9 |
10 | include("smokeTest")
11 | include("java8Test")
12 | include(":jpmsTest")
13 |
14 | rootProject.name = "kotlinx-coroutines-integration-testing"
15 |
--------------------------------------------------------------------------------
/integration-testing/smokeTest/src/commonMain/kotlin/Sample.kt:
--------------------------------------------------------------------------------
1 | import kotlinx.coroutines.*
2 |
3 | suspend fun doWorld() = coroutineScope {
4 | launch {
5 | delay(1000L)
6 | println("World!")
7 | }
8 | println("Hello")
9 | }
10 |
--------------------------------------------------------------------------------
/integration-testing/smokeTest/src/commonTest/kotlin/SampleTest.kt:
--------------------------------------------------------------------------------
1 | import kotlinx.coroutines.test.*
2 | import kotlin.test.*
3 |
4 | class SampleTest {
5 | @Test
6 | fun test() = runTest {
7 | doWorld()
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/integration-testing/src/coreAgentTest/kotlin/CoreAgentTest.kt:
--------------------------------------------------------------------------------
1 | import org.junit.*
2 | import kotlinx.coroutines.*
3 | import kotlinx.coroutines.debug.internal.*
4 | import org.junit.Test
5 | import java.io.*
6 |
7 | class CoreAgentTest {
8 |
9 | @Test
10 | fun testAgentDumpsCoroutines() = runBlocking {
11 | val baos = ByteArrayOutputStream()
12 | @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
13 | DebugProbesImpl.dumpCoroutines(PrintStream(baos))
14 | // if the agent works, then dumps should contain something,
15 | // at least the fact that this test is running.
16 | Assert.assertTrue(baos.toString().contains("testAgentDumpsCoroutines"))
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/integration-testing/src/debugAgentTest/kotlin/DebugAgentTest.kt:
--------------------------------------------------------------------------------
1 | @file:OptIn(ExperimentalCoroutinesApi::class)
2 |
3 | import org.junit.*
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.debug.*
6 | import org.junit.Test
7 | import java.io.*
8 |
9 | class DebugAgentTest {
10 |
11 | @Test
12 | fun testAgentDumpsCoroutines() = runBlocking {
13 | val baos = ByteArrayOutputStream()
14 | DebugProbes.dumpCoroutines(PrintStream(baos))
15 | // if the agent works, then dumps should contain something,
16 | // at least the fact that this test is running.
17 | Assert.assertTrue(baos.toString().contains("testAgentDumpsCoroutines"))
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/integration-testing/src/debugAgentTest/kotlin/DebugProbes.kt:
--------------------------------------------------------------------------------
1 | @file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
2 | package kotlin.coroutines.jvm.internal
3 |
4 | import kotlinx.coroutines.debug.internal.*
5 | import kotlin.coroutines.*
6 |
7 | internal fun probeCoroutineCreated(completion: Continuation): Continuation = DebugProbesImpl.probeCoroutineCreated(completion)
8 |
9 | internal fun probeCoroutineResumed(frame: Continuation<*>) = DebugProbesImpl.probeCoroutineResumed(frame)
10 |
11 | internal fun probeCoroutineSuspended(frame: Continuation<*>) = DebugProbesImpl.probeCoroutineSuspended(frame)
12 |
--------------------------------------------------------------------------------
/integration-testing/src/jvmCoreTest/kotlin/Jdk8InCoreIntegration.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | import kotlinx.coroutines.future.*
4 | import org.junit.Test
5 | import kotlin.test.*
6 |
7 | /*
8 | * Integration test that ensures signatures from both the jdk8 and the core source sets of the kotlinx-coroutines-core subproject are used.
9 | */
10 | class Jdk8InCoreIntegration {
11 |
12 | @Test
13 | fun testFuture() = runBlocking {
14 | val future = future { yield(); 42 }
15 | future.whenComplete { r, _ -> assertEquals(42, r) }
16 | assertEquals(42, future.await())
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/integration/README.md:
--------------------------------------------------------------------------------
1 | # Coroutines integration
2 |
3 | This directory contains modules that provide integration with various asynchronous callback- and future-based libraries.
4 | Module names below correspond to the artifact names in Maven/Gradle.
5 |
6 | ## Modules
7 |
8 | * [kotlinx-coroutines-guava](kotlinx-coroutines-guava/README.md) -- integration with Guava [ListenableFuture](https://github.com/google/guava/wiki/ListenableFutureExplained).
9 | * [kotlinx-coroutines-slf4j](kotlinx-coroutines-slf4j/README.md) -- integration with SLF4J [MDC](https://logback.qos.ch/manual/mdc.html).
10 | * [kotlinx-coroutines-play-services](kotlinx-coroutines-play-services) -- integration with Google Play Services [Tasks API](https://developers.google.com/android/guides/tasks).
11 |
--------------------------------------------------------------------------------
/integration/kotlinx-coroutines-guava/build.gradle.kts:
--------------------------------------------------------------------------------
1 | val guavaVersion = "31.0.1-jre"
2 |
3 | dependencies {
4 | api("com.google.guava:guava:$guavaVersion")
5 | }
6 |
7 | java {
8 | targetCompatibility = JavaVersion.VERSION_1_8
9 | sourceCompatibility = JavaVersion.VERSION_1_8
10 | }
11 |
12 | externalDocumentationLink(
13 | url = "https://google.github.io/guava/releases/$guavaVersion/api/docs/"
14 | )
15 |
--------------------------------------------------------------------------------
/integration/kotlinx-coroutines-guava/package.list:
--------------------------------------------------------------------------------
1 | com.google.common.annotations
2 | com.google.common.base
3 | com.google.common.cache
4 | com.google.common.collect
5 | com.google.common.escape
6 | com.google.common.eventbus
7 | com.google.common.graph
8 | com.google.common.hash
9 | com.google.common.html
10 | com.google.common.io
11 | com.google.common.math
12 | com.google.common.net
13 | com.google.common.primitives
14 | com.google.common.reflect
15 | com.google.common.util.concurrent
16 | com.google.common.xml
17 |
--------------------------------------------------------------------------------
/integration/kotlinx-coroutines-guava/src/module-info.java:
--------------------------------------------------------------------------------
1 | module kotlinx.coroutines.guava {
2 | requires kotlin.stdlib;
3 | requires kotlinx.coroutines.core;
4 | requires com.google.common;
5 |
6 | exports kotlinx.coroutines.guava;
7 | }
8 |
--------------------------------------------------------------------------------
/integration/kotlinx-coroutines-jdk8/README.md:
--------------------------------------------------------------------------------
1 | # Stub module
2 |
3 | Stub module for backwards compatibility. Since 1.7.0, this module was merged with core.
4 |
--------------------------------------------------------------------------------
/integration/kotlinx-coroutines-jdk8/api/kotlinx-coroutines-jdk8.api:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/integration/kotlinx-coroutines-jdk8/api/kotlinx-coroutines-jdk8.api
--------------------------------------------------------------------------------
/integration/kotlinx-coroutines-jdk8/build.gradle.kts:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/integration/kotlinx-coroutines-jdk8/build.gradle.kts
--------------------------------------------------------------------------------
/integration/kotlinx-coroutines-jdk8/src/module-info.java:
--------------------------------------------------------------------------------
1 | @SuppressWarnings("JavaModuleNaming")
2 | module kotlinx.coroutines.jdk8 {
3 | }
4 |
--------------------------------------------------------------------------------
/integration/kotlinx-coroutines-play-services/api/kotlinx-coroutines-play-services.api:
--------------------------------------------------------------------------------
1 | public final class kotlinx/coroutines/tasks/TasksKt {
2 | public static final fun asDeferred (Lcom/google/android/gms/tasks/Task;)Lkotlinx/coroutines/Deferred;
3 | public static final fun asDeferred (Lcom/google/android/gms/tasks/Task;Lcom/google/android/gms/tasks/CancellationTokenSource;)Lkotlinx/coroutines/Deferred;
4 | public static final fun asTask (Lkotlinx/coroutines/Deferred;)Lcom/google/android/gms/tasks/Task;
5 | public static final fun await (Lcom/google/android/gms/tasks/Task;Lcom/google/android/gms/tasks/CancellationTokenSource;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
6 | public static final fun await (Lcom/google/android/gms/tasks/Task;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/integration/kotlinx-coroutines-play-services/build.gradle.kts:
--------------------------------------------------------------------------------
1 | val tasksVersion = "16.0.1"
2 |
3 | project.configureAar()
4 |
5 | dependencies {
6 | configureAarUnpacking()
7 | api("com.google.android.gms:play-services-tasks:$tasksVersion") {
8 | exclude(group="com.android.support")
9 | }
10 |
11 | // Required by robolectric
12 | testImplementation("androidx.test:core:1.2.0")
13 | testImplementation("androidx.test:monitor:1.2.0")
14 | }
15 |
16 | externalDocumentationLink(
17 | url = "https://developers.google.com/android/reference/"
18 | )
19 |
--------------------------------------------------------------------------------
/integration/kotlinx-coroutines-play-services/package.list:
--------------------------------------------------------------------------------
1 | com.google.android.gms.tasks
--------------------------------------------------------------------------------
/integration/kotlinx-coroutines-play-services/test/FakeAndroid.kt:
--------------------------------------------------------------------------------
1 | package android.os
2 |
3 | import kotlinx.coroutines.GlobalScope
4 | import kotlinx.coroutines.launch
5 | import java.util.concurrent.*
6 |
7 | class Handler(val looper: Looper) {
8 | fun post(r: Runnable): Boolean {
9 | try {
10 | GlobalScope.launch { r.run() }
11 | } catch (e: RejectedExecutionException) {
12 | // Execute leftover callbacks in place for tests
13 | r.run()
14 | }
15 |
16 | return true
17 | }
18 | }
19 |
20 | class Looper {
21 | companion object {
22 | @JvmStatic
23 | fun getMainLooper() = Looper()
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/integration/kotlinx-coroutines-slf4j/README.md:
--------------------------------------------------------------------------------
1 | # Module kotlinx-coroutines-slf4j
2 |
3 | Integration with SLF4J [MDC](https://logback.qos.ch/manual/mdc.html).
4 |
5 | ## Example
6 |
7 | Add [MDCContext] to the coroutine context so that the SLF4J MDC context is captured and passed into the coroutine.
8 |
9 | ```kotlin
10 | MDC.put("kotlin", "rocks") // put a value into the MDC context
11 |
12 | launch(MDCContext()) {
13 | logger.info { "..." } // the MDC context will contain the mapping here
14 | }
15 | ```
16 |
17 | # Package kotlinx.coroutines.slf4j
18 |
19 | Integration with SLF4J [MDC](https://logback.qos.ch/manual/mdc.html).
20 |
21 |
22 |
23 |
24 | [MDCContext]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/-m-d-c-context/index.html
25 |
26 |
27 |
--------------------------------------------------------------------------------
/integration/kotlinx-coroutines-slf4j/build.gradle.kts:
--------------------------------------------------------------------------------
1 | dependencies {
2 | implementation("org.slf4j:slf4j-api:1.7.32")
3 | testImplementation("io.github.microutils:kotlin-logging:2.1.0")
4 | testRuntimeOnly("ch.qos.logback:logback-classic:1.2.7")
5 | testRuntimeOnly("ch.qos.logback:logback-core:1.2.7")
6 | }
7 |
8 | externalDocumentationLink(
9 | url = "https://www.slf4j.org/apidocs/"
10 | )
11 |
--------------------------------------------------------------------------------
/integration/kotlinx-coroutines-slf4j/package.list:
--------------------------------------------------------------------------------
1 | org.apache.commons.logging
2 | org.apache.commons.logging.impl
3 | org.apache.log4j
4 | org.apache.log4j.helpers
5 | org.apache.log4j.spi
6 | org.apache.log4j.xml
7 | org.slf4j
8 | org.slf4j.agent
9 | org.slf4j.bridge
10 | org.slf4j.cal10n
11 | org.slf4j.event
12 | org.slf4j.ext
13 | org.slf4j.helpers
14 | org.slf4j.instrumentation
15 | org.slf4j.jul
16 | org.slf4j.log4j12
17 | org.slf4j.nop
18 | org.slf4j.osgi.logservice.impl
19 | org.slf4j.profiler
20 | org.slf4j.simple
21 | org.slf4j.spi
22 |
--------------------------------------------------------------------------------
/integration/kotlinx-coroutines-slf4j/src/module-info.java:
--------------------------------------------------------------------------------
1 | module kotlinx.coroutines.slf4j {
2 | requires kotlin.stdlib;
3 | requires kotlinx.coroutines.core;
4 | requires org.slf4j;
5 |
6 | exports kotlinx.coroutines.slf4j;
7 | }
8 |
--------------------------------------------------------------------------------
/integration/kotlinx-coroutines-slf4j/test-resources/logback-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %X{first} %X{last} - %m%n
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/knit.properties:
--------------------------------------------------------------------------------
1 | knit.include=docs/knit.code.include
2 | test.template=docs/knit.test.template
3 |
4 | # Various test validation modes and their corresponding methods from TestUtil
5 | test.mode.=verifyLines
6 | test.mode.STARTS_WITH=verifyLinesStartWith
7 | test.mode.ARBITRARY_TIME=verifyLinesArbitraryTime
8 | test.mode.FLEXIBLE_TIME=verifyLinesFlexibleTime
9 | test.mode.FLEXIBLE_THREAD=verifyLinesFlexibleThread
10 | test.mode.LINES_START_UNORDERED=verifyLinesStartUnordered
11 | test.mode.LINES_START=verifyLinesStart
12 | test.mode.EXCEPTION=verifyExceptions
13 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/benchmarks/README.md:
--------------------------------------------------------------------------------
1 | ## kotlinx-coroutines-core benchmarks
2 |
3 | Multiplatform benchmarks for kotlinx-coroutines-core.
4 |
5 | This source-set contains benchmarks that leverage `internal` API (e.g. `suspendCancellableCoroutineReusable`) or
6 | that are multiplatform (-> only supported with `kotlinx-benchmarks` which is less convenient than `jmh` plugin).
7 | For JVM-only non-internal benchmarks, consider using `benchmarks` top-level project.
8 |
9 | ### Usage
10 |
11 | ```
12 | // JVM only
13 | ./gradlew :kotlinx-coroutines-core:jvmBenchmarkBenchmarkJar
14 | java -jar kotlinx-coroutines-core/build/benchmarks/jvmBenchmark/jars/kotlinx-coroutines-core-jvmBenchmark-jmh-*-JMH.jar
15 |
16 | // Native, OS X
17 | ./gradlew :kotlinx-coroutines-core:macosArm64BenchmarkBenchmark
18 |
19 | // Figure out what to use
20 | ./gradlew :kotlinx-coroutines-core:tasks | grep -i bench
21 | ```
22 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/benchmarks/jvm/kotlin/kotlinx/coroutines/BenchmarkUtils.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | import java.util.concurrent.*
4 |
5 | public fun doGeomDistrWork(work: Int) {
6 | // We use geometric distribution here. We also checked on macbook pro 13" (2017) that the resulting work times
7 | // are distributed geometrically, see https://github.com/Kotlin/kotlinx.coroutines/pull/1464#discussion_r355705325
8 | val p = 1.0 / work
9 | val r = ThreadLocalRandom.current()
10 | while (true) {
11 | if (r.nextDouble() < p) break
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/benchmarks/main/kotlin/SharedFlowBaseline.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | import kotlinx.coroutines.*
4 | import kotlinx.coroutines.flow.*
5 | import kotlinx.benchmark.*
6 |
7 | // Stresses out 'syncrhonozed' codepath in MutableSharedFlow
8 | @State(Scope.Benchmark)
9 | @Measurement(iterations = 3, time = 1, timeUnit = BenchmarkTimeUnit.SECONDS)
10 | @OutputTimeUnit(BenchmarkTimeUnit.MICROSECONDS)
11 | @BenchmarkMode(Mode.AverageTime)
12 | open class SharedFlowBaseline {
13 | private var size: Int = 10_000
14 |
15 | @Benchmark
16 | fun baseline() = runBlocking {
17 | val flow = MutableSharedFlow()
18 | launch {
19 | repeat(size) { flow.emit(Unit) }
20 | }
21 |
22 | flow.take(size).collect { }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/common/src/CoroutineName.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | import kotlin.coroutines.AbstractCoroutineContextElement
4 | import kotlin.coroutines.CoroutineContext
5 |
6 | /**
7 | * User-specified name of coroutine. This name is used in debugging mode.
8 | * See [newCoroutineContext][CoroutineScope.newCoroutineContext] for the description of coroutine debugging facilities.
9 | */
10 | public data class CoroutineName(
11 | /**
12 | * User-defined coroutine name.
13 | */
14 | val name: String
15 | ) : AbstractCoroutineContextElement(CoroutineName) {
16 | /**
17 | * Key for [CoroutineName] instance in the coroutine context.
18 | */
19 | public companion object Key : CoroutineContext.Key
20 |
21 | /**
22 | * Returns a string representation of the object.
23 | */
24 | override fun toString(): String = "CoroutineName($name)"
25 | }
26 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/common/src/Runnable.common.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | /**
4 | * A runnable task for [CoroutineDispatcher.dispatch].
5 | *
6 | * It is equivalent to the type `() -> Unit`, but on the JVM, it is represented as a `java.lang.Runnable`,
7 | * making it easier to wrap the interfaces that expect `java.lang.Runnable` into a [CoroutineDispatcher].
8 | */
9 | public expect fun interface Runnable {
10 | /**
11 | * @suppress
12 | */
13 | public fun run()
14 | }
15 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/common/src/Waiter.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | import kotlinx.coroutines.internal.Segment
4 | import kotlinx.coroutines.selects.*
5 |
6 | /**
7 | * All waiters (such as [CancellableContinuationImpl] and [SelectInstance]) in synchronization and
8 | * communication primitives, should implement this interface to make the code faster and easier to read.
9 | */
10 | internal interface Waiter {
11 | /**
12 | * When this waiter is cancelled, [Segment.onCancellation] with
13 | * the specified [segment] and [index] should be called.
14 | * This function installs the corresponding cancellation handler.
15 | */
16 | fun invokeOnCancellation(segment: Segment<*>, index: Int)
17 | }
18 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/common/src/flow/internal/NopCollector.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.flow.internal
2 |
3 | import kotlinx.coroutines.flow.*
4 |
5 | internal object NopCollector : FlowCollector {
6 | override suspend fun emit(value: Any?) {
7 | // does nothing
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/common/src/flow/internal/NullSurrogate.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.flow.internal
2 |
3 | import kotlinx.coroutines.internal.*
4 | import kotlin.jvm.*
5 |
6 | /**
7 | * This value is used a a surrogate `null` value when needed.
8 | * It should never leak to the outside world.
9 | * Its usage typically are paired with [Symbol.unbox] usages.
10 | */
11 | @JvmField
12 | internal val NULL = Symbol("NULL")
13 |
14 | /**
15 | * Symbol to indicate that the value is not yet initialized.
16 | * It should never leak to the outside world.
17 | */
18 | @JvmField
19 | internal val UNINITIALIZED = Symbol("UNINITIALIZED")
20 |
21 | /*
22 | * Symbol used to indicate that the flow is complete.
23 | * It should never leak to the outside world.
24 | */
25 | @JvmField
26 | internal val DONE = Symbol("DONE")
27 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/common/src/flow/internal/SendingCollector.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.flow.internal
2 |
3 | import kotlinx.coroutines.*
4 | import kotlinx.coroutines.channels.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | /**
8 | * Collection that sends to channel
9 | * @suppress **This an internal API and should not be used from general code.**
10 | */
11 | @InternalCoroutinesApi
12 | public class SendingCollector(
13 | private val channel: SendChannel
14 | ) : FlowCollector {
15 | override suspend fun emit(value: T): Unit = channel.send(value)
16 | }
17 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/common/src/flow/terminal/Collection.kt:
--------------------------------------------------------------------------------
1 | @file:JvmMultifileClass
2 | @file:JvmName("FlowKt")
3 |
4 | package kotlinx.coroutines.flow
5 |
6 | import kotlin.jvm.*
7 |
8 | /**
9 | * Collects given flow into a [destination]
10 | */
11 | public suspend fun Flow.toList(destination: MutableList = ArrayList()): List = toCollection(destination)
12 |
13 | /**
14 | * Collects given flow into a [destination]
15 | */
16 | public suspend fun Flow.toSet(destination: MutableSet = LinkedHashSet()): Set = toCollection(destination)
17 |
18 | /**
19 | * Collects given flow into a [destination]
20 | */
21 | public suspend fun > Flow.toCollection(destination: C): C {
22 | collect { value ->
23 | destination.add(value)
24 | }
25 | return destination
26 | }
27 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/common/src/flow/terminal/Count.kt:
--------------------------------------------------------------------------------
1 | @file:JvmMultifileClass
2 | @file:JvmName("FlowKt")
3 |
4 | package kotlinx.coroutines.flow
5 |
6 | import kotlin.jvm.*
7 |
8 | /**
9 | * Returns the number of elements in this flow.
10 | */
11 | public suspend fun Flow.count(): Int {
12 | var i = 0
13 | collect {
14 | ++i
15 | }
16 |
17 | return i
18 | }
19 |
20 | /**
21 | * Returns the number of elements matching the given predicate.
22 | */
23 | public suspend fun Flow.count(predicate: suspend (T) -> Boolean): Int {
24 | var i = 0
25 | collect { value ->
26 | if (predicate(value)) {
27 | ++i
28 | }
29 | }
30 |
31 | return i
32 | }
33 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/common/src/internal/InternalAnnotations.common.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | // Ignore JRE requirements for animal-sniffer, compileOnly dependency
4 | @Target(
5 | AnnotationTarget.FUNCTION,
6 | AnnotationTarget.PROPERTY_GETTER,
7 | AnnotationTarget.PROPERTY_SETTER,
8 | AnnotationTarget.CONSTRUCTOR,
9 | AnnotationTarget.CLASS,
10 | AnnotationTarget.FILE
11 | )
12 | @OptionalExpectation
13 | internal expect annotation class IgnoreJreRequirement()
14 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/common/src/internal/LocalAtomics.common.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | /*
4 | * These are atomics that are used as local variables
5 | * where atomicfu doesn't support its tranformations.
6 | *
7 | * Have `Local` prefix to avoid AFU clashes during star-imports
8 | *
9 | * TODO: remove after https://youtrack.jetbrains.com/issue/KT-62423/
10 | */
11 | internal expect class LocalAtomicInt(value: Int) {
12 | fun get(): Int
13 | fun set(value: Int)
14 | fun decrementAndGet(): Int
15 | }
16 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/common/src/internal/ProbesSupport.common.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | import kotlin.coroutines.*
4 |
5 | internal expect inline fun probeCoroutineCreated(completion: Continuation): Continuation
6 |
7 | internal expect inline fun probeCoroutineResumed(completion: Continuation): Unit
8 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/common/src/internal/Symbol.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | import kotlin.jvm.*
4 |
5 | /**
6 | * A symbol class that is used to define unique constants that are self-explanatory in debugger.
7 | *
8 | * @suppress **This is unstable API and it is subject to change.**
9 | */
10 | internal class Symbol(@JvmField val symbol: String) {
11 | override fun toString(): String = "<$symbol>"
12 |
13 | @Suppress("UNCHECKED_CAST", "NOTHING_TO_INLINE")
14 | inline fun unbox(value: Any?): T = if (value === this) null as T else value as T
15 | }
16 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/common/src/internal/ThreadContext.common.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | import kotlin.coroutines.*
4 |
5 | internal expect fun threadContextElements(context: CoroutineContext): Any
6 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/common/src/internal/ThreadLocal.common.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | internal expect class CommonThreadLocal {
4 | fun get(): T
5 | fun set(value: T)
6 | }
7 |
8 | /**
9 | * Create a thread-local storage for an object of type [T].
10 | *
11 | * If two different thread-local objects share the same [name], they will not necessarily share the same value,
12 | * but they may.
13 | * Therefore, use a unique [name] for each thread-local object.
14 | */
15 | internal expect fun commonThreadLocal(name: Symbol): CommonThreadLocal
16 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/common/src/selects/WhileSelect.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.selects
2 |
3 | import kotlinx.coroutines.*
4 |
5 | /**
6 | * Loops while [select] expression returns `true`.
7 | *
8 | * The statement of the form:
9 | *
10 | * ```
11 | * whileSelect {
12 | * /*body*/
13 | * }
14 | * ```
15 | *
16 | * is a shortcut for:
17 | *
18 | * ```
19 | * while(select {
20 | * /*body*/
21 | * }) {}
22 | *
23 | * **Note: This is an experimental api.** It may be replaced with a higher-performance DSL for selection from loops.
24 | */
25 | @ExperimentalCoroutinesApi
26 | public suspend inline fun whileSelect(crossinline builder: SelectBuilder.() -> Unit) {
27 | while(select(builder)) { /* do nothing */ }
28 | }
29 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/common/test/AwaitCancellationTest.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | import kotlinx.coroutines.testing.*
4 | import kotlin.test.*
5 |
6 | class AwaitCancellationTest : TestBase() {
7 |
8 | @Test
9 | fun testCancellation() = runTest(expected = { it is CancellationException }) {
10 | expect(1)
11 | coroutineScope {
12 | val deferred: Deferred = async {
13 | expect(2)
14 | awaitCancellation()
15 | }
16 | yield()
17 | expect(3)
18 | require(deferred.isActive)
19 | deferred.cancel()
20 | finish(4)
21 | deferred.await()
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/common/test/flow/SafeFlowTest.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.flow
2 |
3 | import kotlinx.coroutines.testing.*
4 | import kotlinx.coroutines.*
5 | import kotlin.test.*
6 |
7 | class SafeFlowTest : TestBase() {
8 |
9 | @Test
10 | fun testEmissionsFromDifferentStateMachine() = runTest {
11 | val result = flow {
12 | emit1(1)
13 | emit2(2)
14 | }.onEach { yield() }.toList()
15 | assertEquals(listOf(1, 2), result)
16 | finish(3)
17 | }
18 |
19 | private suspend fun FlowCollector.emit1(expect: Int) {
20 | emit(expect)
21 | expect(expect)
22 | }
23 |
24 | private suspend fun FlowCollector.emit2(expect: Int) {
25 | emit(expect)
26 | expect(expect)
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/common/test/flow/operators/ConflateTest.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.flow
2 |
3 | import kotlinx.coroutines.testing.*
4 | import kotlinx.coroutines.*
5 | import kotlin.test.*
6 |
7 | class ConflateTest : TestBase() {
8 | @Test // from example
9 | fun testExample() = withVirtualTime {
10 | expect(1)
11 | val flow = flow {
12 | for (i in 1..30) {
13 | delay(100)
14 | emit(i)
15 | }
16 | }
17 | val result = flow.conflate().onEach {
18 | delay(1000)
19 | }.toList()
20 | assertEquals(listOf(1, 10, 20, 30), result)
21 | finish(2)
22 | }
23 | }
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/common/test/flow/operators/TransformTest.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.flow
2 |
3 | import kotlinx.coroutines.testing.*
4 | import kotlinx.coroutines.*
5 | import kotlin.test.*
6 |
7 | class TransformTest : TestBase() {
8 | @Test
9 | fun testDoubleEmit() = runTest {
10 | val flow = flowOf(1, 2, 3)
11 | .transform {
12 | emit(it)
13 | emit(it)
14 | }
15 | assertEquals(listOf(1, 1, 2, 2, 3, 3), flow.toList())
16 | }
17 | }
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/common/test/flow/terminal/ToCollectionTest.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.flow
2 |
3 | import kotlinx.coroutines.testing.*
4 | import kotlinx.coroutines.*
5 | import kotlin.test.*
6 |
7 | class ToCollectionTest : TestBase() {
8 |
9 | private val flow = flow {
10 | repeat(10) {
11 | emit(42)
12 | }
13 | }
14 |
15 | private val emptyFlow = flowOf()
16 |
17 | @Test
18 | fun testToList() = runTest {
19 | assertEquals(List(10) { 42 }, flow.toList())
20 | assertEquals(emptyList(), emptyFlow.toList())
21 | }
22 |
23 | @Test
24 | fun testToSet() = runTest {
25 | assertEquals(setOf(42), flow.toSet())
26 | assertEquals(emptySet(), emptyFlow.toSet())
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/common/test/selects/SelectUnlimitedChannelTest.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.selects
2 |
3 | import kotlinx.coroutines.testing.*
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.channels.*
6 | import kotlin.test.*
7 |
8 | class SelectUnlimitedChannelTest : TestBase() {
9 | @Test
10 | fun testSelectSendWhenClosed() = runTest {
11 | expect(1)
12 | val c = Channel(Channel.UNLIMITED)
13 | c.send(1) // enqueue buffered element
14 | c.close() // then close
15 | assertFailsWith {
16 | // select sender should fail
17 | expect(2)
18 | select {
19 | c.onSend(2) {
20 | expectUnreached()
21 | }
22 | }
23 | }
24 | finish(3)
25 | }
26 | }
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/concurrent/test/DefaultDispatchersConcurrencyTest.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | class DefaultDispatcherConcurrencyTest : AbstractDispatcherConcurrencyTest() {
4 | override val dispatcher: CoroutineDispatcher = Dispatchers.Default
5 | }
6 |
7 | class IoDispatcherConcurrencyTest : AbstractDispatcherConcurrencyTest() {
8 | override val dispatcher: CoroutineDispatcher = Dispatchers.IO
9 | }
10 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/js/src/Debug.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | private var counter = 0
4 |
5 | internal actual val DEBUG: Boolean = false
6 |
7 | internal actual val Any.hexAddress: String
8 | get() {
9 | var result = this.asDynamic().__debug_counter
10 | if (jsTypeOf(result) !== "number") {
11 | result = ++counter
12 | this.asDynamic().__debug_counter = result
13 |
14 | }
15 | return (result as Int).toString()
16 | }
17 |
18 | internal actual val Any.classSimpleName: String get() = this::class.simpleName ?: "Unknown"
19 |
20 | internal actual inline fun assert(value: () -> Boolean) {}
21 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/js/src/internal/CoroutineExceptionHandlerImpl.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | import kotlinx.coroutines.*
4 |
5 | internal actual fun propagateExceptionFinalResort(exception: Throwable) {
6 | // log exception
7 | console.error(exception.toString())
8 | }
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jsAndWasmShared/src/CloseableCoroutineDispatcher.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | public actual abstract class CloseableCoroutineDispatcher actual constructor() : CoroutineDispatcher(), AutoCloseable {
4 | public actual abstract override fun close()
5 | }
6 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jsAndWasmShared/src/Runnable.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | /**
4 | * A runnable task for [CoroutineDispatcher.dispatch].
5 | *
6 | * Equivalent to the type `() -> Unit`.
7 | */
8 | public actual fun interface Runnable {
9 | /**
10 | * @suppress
11 | */
12 | public actual fun run()
13 | }
14 |
15 | @Deprecated(
16 | "Preserved for binary compatibility, see https://github.com/Kotlin/kotlinx.coroutines/issues/4309",
17 | level = DeprecationLevel.HIDDEN
18 | )
19 | public inline fun Runnable(crossinline block: () -> Unit): Runnable =
20 | object : Runnable {
21 | override fun run() {
22 | block()
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jsAndWasmShared/src/SchedulerTask.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | internal actual abstract class SchedulerTask : Runnable
4 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jsAndWasmShared/src/flow/internal/FlowExceptions.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.flow.internal
2 |
3 | import kotlinx.coroutines.*
4 | import kotlinx.coroutines.flow.*
5 |
6 | internal actual class AbortFlowException actual constructor(
7 | actual val owner: Any
8 | ) : CancellationException("Flow was aborted, no more elements needed")
9 | internal actual class ChildCancelledException : CancellationException("Child of the scoped flow was cancelled")
10 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jsAndWasmShared/src/internal/CoroutineExceptionHandlerImpl.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | import kotlinx.coroutines.*
4 | import kotlin.coroutines.*
5 |
6 | private val platformExceptionHandlers_ = mutableSetOf()
7 |
8 | internal actual val platformExceptionHandlers: Collection
9 | get() = platformExceptionHandlers_
10 |
11 | internal actual fun ensurePlatformExceptionHandlerLoaded(callback: CoroutineExceptionHandler) {
12 | platformExceptionHandlers_ += callback
13 | }
14 |
15 | internal actual class DiagnosticCoroutineContextException actual constructor(context: CoroutineContext) :
16 | RuntimeException(context.toString())
17 |
18 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jsAndWasmShared/src/internal/LocalAtomics.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | internal actual class LocalAtomicInt actual constructor(private var value: Int) {
4 | actual fun set(value: Int) {
5 | this.value = value
6 | }
7 |
8 | actual fun get(): Int = value
9 |
10 | actual fun decrementAndGet(): Int = --value
11 | }
12 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jsAndWasmShared/src/internal/ProbesSupport.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | import kotlin.coroutines.*
4 |
5 | @Suppress("NOTHING_TO_INLINE")
6 | internal actual inline fun probeCoroutineCreated(completion: Continuation): Continuation = completion
7 |
8 | @Suppress("NOTHING_TO_INLINE")
9 | internal actual inline fun probeCoroutineResumed(completion: Continuation) { }
10 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jsAndWasmShared/src/internal/Synchronized.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | import kotlinx.coroutines.*
4 |
5 | /**
6 | * @suppress **This an internal API and should not be used from general code.**
7 | */
8 | @InternalCoroutinesApi
9 | public actual open class SynchronizedObject
10 |
11 | /**
12 | * @suppress **This an internal API and should not be used from general code.**
13 | */
14 | @InternalCoroutinesApi
15 | public actual inline fun synchronizedImpl(lock: SynchronizedObject, block: () -> T): T = block()
16 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jsAndWasmShared/src/internal/SystemProps.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | internal actual fun systemProp(propertyName: String): String? = null
4 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jsAndWasmShared/src/internal/ThreadContext.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | import kotlin.coroutines.*
4 |
5 | internal actual fun threadContextElements(context: CoroutineContext): Any = 0
6 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jsAndWasmShared/src/internal/ThreadLocal.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | internal actual class CommonThreadLocal {
4 | private var value: T? = null
5 | @Suppress("UNCHECKED_CAST")
6 | actual fun get(): T = value as T
7 | actual fun set(value: T) { this.value = value }
8 | }
9 |
10 | internal actual fun commonThreadLocal(name: Symbol): CommonThreadLocal = CommonThreadLocal()
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/resources/DebugProbesKt.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/kotlinx-coroutines-core/jvm/resources/DebugProbesKt.bin
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/src/DebugStrings.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | import kotlinx.coroutines.internal.*
4 | import kotlin.coroutines.*
5 |
6 | // internal debugging tools for string representation
7 |
8 | internal actual val Any.hexAddress: String
9 | get() = Integer.toHexString(System.identityHashCode(this))
10 |
11 | internal actual fun Continuation<*>.toDebugString(): String = when (this) {
12 | is DispatchedContinuation -> toString()
13 | // Workaround for #858
14 | else -> runCatching { "$this@$hexAddress" }.getOrElse { "${this::class.java.name}@$hexAddress" }
15 | }
16 |
17 | internal actual val Any.classSimpleName: String get() = this::class.java.simpleName
18 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/src/Runnable.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | /**
4 | * A runnable task for [CoroutineDispatcher.dispatch].
5 | *
6 | * It is a typealias for [java.lang.Runnable], which is widely used in Java APIs.
7 | * This makes it possible to directly pass the argument of [CoroutineDispatcher.dispatch]
8 | * to the underlying Java implementation without any additional wrapping.
9 | */
10 | public actual typealias Runnable = java.lang.Runnable
11 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/src/SchedulerTask.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | import kotlinx.coroutines.scheduling.*
4 |
5 | internal actual typealias SchedulerTask = Task
6 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/src/ThreadPoolDispatcher.kt:
--------------------------------------------------------------------------------
1 | @file:JvmMultifileClass
2 | @file:JvmName("ThreadPoolDispatcherKt")
3 | package kotlinx.coroutines
4 |
5 | import java.util.concurrent.*
6 | import java.util.concurrent.atomic.AtomicInteger
7 |
8 | @DelicateCoroutinesApi
9 | public actual fun newFixedThreadPoolContext(nThreads: Int, name: String): ExecutorCoroutineDispatcher {
10 | require(nThreads >= 1) { "Expected at least one thread, but $nThreads specified" }
11 | val threadNo = AtomicInteger()
12 | val executor = Executors.newScheduledThreadPool(nThreads) { runnable ->
13 | Thread(runnable, if (nThreads == 1) name else name + "-" + threadNo.incrementAndGet())
14 | .apply { isDaemon = true }
15 | }
16 | return Executors.unconfigurableExecutorService(executor).asCoroutineDispatcher()
17 | }
18 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/src/debug/internal/StackTraceFrame.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.debug.internal
2 |
3 | import kotlin.coroutines.jvm.internal.*
4 |
5 | /**
6 | * A stack-trace represented as [CoroutineStackFrame].
7 | */
8 | internal class StackTraceFrame(
9 | override val callerFrame: CoroutineStackFrame?,
10 | private val stackTraceElement: StackTraceElement
11 | ) : CoroutineStackFrame {
12 | override fun getStackTraceElement(): StackTraceElement = stackTraceElement
13 | }
14 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/src/internal/InternalAnnotations.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | internal actual typealias IgnoreJreRequirement = org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
4 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/src/internal/LocalAtomics.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | internal actual typealias LocalAtomicInt = java.util.concurrent.atomic.AtomicInteger
4 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/src/internal/ProbesSupport.kt:
--------------------------------------------------------------------------------
1 | @file:Suppress("NOTHING_TO_INLINE", "INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
2 |
3 | package kotlinx.coroutines.internal
4 |
5 | import kotlin.coroutines.*
6 |
7 | internal actual inline fun probeCoroutineCreated(completion: Continuation): Continuation =
8 | kotlin.coroutines.jvm.internal.probeCoroutineCreated(completion)
9 |
10 | internal actual inline fun probeCoroutineResumed(completion: Continuation) {
11 | kotlin.coroutines.jvm.internal.probeCoroutineResumed(completion)
12 | }
13 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/src/internal/Synchronized.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | import kotlinx.coroutines.*
4 |
5 | /**
6 | * @suppress **This an internal API and should not be used from general code.**
7 | */
8 | @InternalCoroutinesApi
9 | public actual typealias SynchronizedObject = Any
10 |
11 | /**
12 | * @suppress **This an internal API and should not be used from general code.**
13 | */
14 | @InternalCoroutinesApi
15 | public actual inline fun synchronizedImpl(lock: SynchronizedObject, block: () -> T): T =
16 | kotlin.synchronized(lock, block)
17 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/src/internal/SystemProps.kt:
--------------------------------------------------------------------------------
1 | @file:JvmName("SystemPropsKt")
2 | @file:JvmMultifileClass
3 |
4 | package kotlinx.coroutines.internal
5 |
6 | // number of processors at startup for consistent prop initialization
7 | internal val AVAILABLE_PROCESSORS = Runtime.getRuntime().availableProcessors()
8 |
9 | internal actual fun systemProp(
10 | propertyName: String
11 | ): String? =
12 | try {
13 | System.getProperty(propertyName)
14 | } catch (e: SecurityException) {
15 | null
16 | }
17 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/src/internal/ThreadLocal.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | import java.lang.ThreadLocal
4 |
5 | internal actual typealias CommonThreadLocal = ThreadLocal
6 |
7 | internal actual fun commonThreadLocal(name: Symbol): CommonThreadLocal = ThreadLocal()
8 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test-resources/stacktraces/channels/testReceiveFromClosedChannel.txt:
--------------------------------------------------------------------------------
1 | kotlinx.coroutines.testing.RecoverableTestException
2 | at kotlinx.coroutines.exceptions.StackTraceRecoveryChannelsTest$testReceiveFromClosedChannel$1.invokeSuspend(StackTraceRecoveryChannelsTest.kt:110)
3 | at _COROUTINE._BOUNDARY._(CoroutineDebugging.kt)
4 | at kotlinx.coroutines.exceptions.StackTraceRecoveryChannelsTest.channelReceive(StackTraceRecoveryChannelsTest.kt:116)
5 | at kotlinx.coroutines.exceptions.StackTraceRecoveryChannelsTest$testReceiveFromClosedChannel$1.invokeSuspend(StackTraceRecoveryChannelsTest.kt:111)
6 | Caused by: kotlinx.coroutines.testing.RecoverableTestException
7 | at kotlinx.coroutines.exceptions.StackTraceRecoveryChannelsTest$testReceiveFromClosedChannel$1.invokeSuspend(StackTraceRecoveryChannelsTest.kt:110)
8 | at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
9 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test-resources/stacktraces/channels/testSendToClosedChannel.txt:
--------------------------------------------------------------------------------
1 | kotlinx.coroutines.testing.RecoverableTestException
2 | at kotlinx.coroutines.exceptions.StackTraceRecoveryChannelsTest$testSendToClosedChannel$1.invokeSuspend(StackTraceRecoveryChannelsTest.kt:43)
3 | at _COROUTINE._BOUNDARY._(CoroutineDebugging.kt)
4 | at kotlinx.coroutines.exceptions.StackTraceRecoveryChannelsTest.channelSend(StackTraceRecoveryChannelsTest.kt:74)
5 | at kotlinx.coroutines.exceptions.StackTraceRecoveryChannelsTest$testSendToClosedChannel$1.invokeSuspend(StackTraceRecoveryChannelsTest.kt:44)
6 | Caused by: kotlinx.coroutines.testing.RecoverableTestException
7 | at kotlinx.coroutines.exceptions.StackTraceRecoveryChannelsTest$testSendToClosedChannel$1.invokeSuspend(StackTraceRecoveryChannelsTest.kt:43)
8 | at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
9 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test-resources/stacktraces/select/testSelectCompletedAwait.txt:
--------------------------------------------------------------------------------
1 | kotlinx.coroutines.testing.RecoverableTestException
2 | at kotlinx.coroutines.exceptions.StackTraceRecoverySelectTest$testSelectCompletedAwait$1.invokeSuspend(StackTraceRecoverySelectTest.kt:40)
3 | at _COROUTINE._BOUNDARY._(CoroutineDebugging.kt)
4 | at kotlinx.coroutines.exceptions.StackTraceRecoverySelectTest$testSelectCompletedAwait$1.invokeSuspend(StackTraceRecoverySelectTest.kt:41)
5 | Caused by: kotlinx.coroutines.testing.RecoverableTestException
6 | at kotlinx.coroutines.exceptions.StackTraceRecoverySelectTest$testSelectCompletedAwait$1.invokeSuspend(StackTraceRecoverySelectTest.kt:40)
7 | at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
8 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test-resources/stacktraces/select/testSelectJoin.txt:
--------------------------------------------------------------------------------
1 | kotlinx.coroutines.testing.RecoverableTestException
2 | at kotlinx.coroutines.exceptions.StackTraceRecoverySelectTest$doSelect$2$1.invokeSuspend(StackTraceRecoverySelectTest.kt)
3 | at _COROUTINE._BOUNDARY._(CoroutineDebugging.kt)
4 | at kotlinx.coroutines.selects.SelectImplementation.processResultAndInvokeBlockRecoveringException(Select.kt)
5 | at kotlinx.coroutines.exceptions.StackTraceRecoverySelectTest$testSelectJoin$1.invokeSuspend(StackTraceRecoverySelectTest.kt)
6 | Caused by: kotlinx.coroutines.testing.RecoverableTestException
7 | at kotlinx.coroutines.exceptions.StackTraceRecoverySelectTest$doSelect$2$1.invokeSuspend(StackTraceRecoverySelectTest.kt)
8 | at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt)
9 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test-resources/stacktraces/timeout/testStacktraceIsRecoveredFromLexicalBlockWhenTriggeredByChild.txt:
--------------------------------------------------------------------------------
1 | kotlinx.coroutines.TimeoutCancellationException: Timed out waiting for 200 ms
2 | at _COROUTINE._BOUNDARY._(CoroutineDebugging.kt)
3 | at kotlinx.coroutines.exceptions.StackTraceRecoveryWithTimeoutTest.outerChildWithTimeout(StackTraceRecoveryWithTimeoutTest.kt:48)
4 | at kotlinx.coroutines.exceptions.StackTraceRecoveryWithTimeoutTest$testStacktraceIsRecoveredFromLexicalBlockWhenTriggeredByChild$1.invokeSuspend(StackTraceRecoveryWithTimeoutTest.kt:40)
5 | Caused by: kotlinx.coroutines.TimeoutCancellationException: Timed out waiting for 200 ms
6 | at kotlinx.coroutines.TimeoutKt.TimeoutCancellationException(Timeout.kt:116)
7 | at kotlinx.coroutines.TimeoutCoroutine.run(Timeout.kt:86)
8 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/AwaitJvmTest.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | import kotlinx.coroutines.testing.*
4 | import org.junit.*
5 |
6 | class AwaitJvmTest : TestBase() {
7 | @Test
8 | public fun testSecondLeak() = runTest {
9 | // This test is to make sure that handlers installed on the second deferred do not leak
10 | val d1 = CompletableDeferred()
11 | val d2 = CompletableDeferred()
12 | d1.completeExceptionally(TestException()) // first is crashed
13 | val iterations = 3_000_000 * stressTestMultiplier
14 | for (iter in 1..iterations) {
15 | try {
16 | awaitAll(d1, d2)
17 | expectUnreached()
18 | } catch (e: TestException) {
19 | expect(iter)
20 | }
21 | }
22 | finish(iterations + 1)
23 | }
24 | }
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/ConcurrentTestUtilities.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.exceptions
2 |
3 | actual inline fun yieldThread() { Thread.yield() }
4 |
5 | actual fun currentThreadName(): String = Thread.currentThread().name
6 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/IODispatcherTest.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | import kotlinx.coroutines.testing.*
4 | import org.junit.Test
5 | import kotlin.test.*
6 |
7 | class IODispatcherTest : TestBase() {
8 | @Test
9 | fun testWithIOContext() = runTest {
10 | // just a very basic test that is dispatcher works and indeed uses background thread
11 | val mainThread = Thread.currentThread()
12 | expect(1)
13 | withContext(Dispatchers.IO) {
14 | expect(2)
15 | assertNotSame(mainThread, Thread.currentThread())
16 | }
17 |
18 | expect(3)
19 | assertSame(mainThread, Thread.currentThread())
20 | finish(4)
21 | }
22 | }
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/JobStressTest.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | import kotlinx.coroutines.testing.*
4 | import kotlin.test.*
5 |
6 | class JobStressTest : TestBase() {
7 | @Test
8 | fun testMemoryRelease() {
9 | val job = Job()
10 | val n = 10_000_000 * stressTestMultiplier
11 | var fireCount = 0
12 | for (i in 0 until n) job.invokeOnCompletion { fireCount++ }.dispose()
13 | }
14 | }
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/TestBaseTest.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | import kotlinx.coroutines.testing.*
4 | import org.junit.*
5 |
6 | class TestBaseTest : TestBase() {
7 | @Test
8 | fun testThreadsShutdown() {
9 | repeat(1000 * stressTestMultiplier) { _ ->
10 | initPoolsBeforeTest()
11 | val threadsBefore = currentThreads()
12 | runBlocking {
13 | val sub = launch {
14 | delay(10000000L)
15 | }
16 | sub.cancel()
17 | sub.join()
18 | }
19 | shutdownPoolsAfterTest()
20 | checkTestThreads(threadsBefore)
21 | }
22 |
23 | }
24 | }
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/WithDefaultContextTest.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | import kotlinx.coroutines.testing.*
4 | import kotlin.test.*
5 |
6 | class WithDefaultContextTest : TestBase() {
7 | @Test
8 | fun testNoSuspend() = runTest {
9 | expect(1)
10 | val result = withContext(Dispatchers.Default) {
11 | expect(2)
12 | "OK"
13 | }
14 | assertEquals("OK", result)
15 | finish(3)
16 | }
17 |
18 | @Test
19 | fun testWithSuspend() = runTest {
20 | expect(1)
21 | val result = withContext(Dispatchers.Default) {
22 | expect(2)
23 | delay(100)
24 | expect(3)
25 | "OK"
26 | }
27 | assertEquals("OK", result)
28 | finish(4)
29 | }
30 | }
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/channels/ChannelMemoryLeakStressTest.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.channels
2 |
3 | import kotlinx.coroutines.testing.*
4 | import kotlinx.coroutines.*
5 | import org.junit.Test
6 |
7 | class ChannelMemoryLeakStressTest : TestBase() {
8 | private val nRepeat = 1_000_000 * stressTestMultiplier
9 |
10 | @Test
11 | fun test() = runTest {
12 | val c = Channel(1)
13 | repeat(nRepeat) {
14 | c.send(bigValue())
15 | c.receive()
16 | }
17 | }
18 |
19 | // capture big value for fast OOM in case of a bug
20 | private fun bigValue(): ByteArray = ByteArray(4096)
21 | }
22 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/examples/example-delay-01.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from Delay.kt by Knit tool. Do not edit.
2 | package kotlinx.coroutines.examples.exampleDelay01
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 | import kotlin.time.Duration.Companion.milliseconds
7 |
8 | fun main() = runBlocking {
9 |
10 | flow {
11 | emit(1)
12 | delay(90)
13 | emit(2)
14 | delay(90)
15 | emit(3)
16 | delay(1010)
17 | emit(4)
18 | delay(1010)
19 | emit(5)
20 | }.debounce(1000)
21 | .toList().joinToString().let { println(it) } }
22 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/examples/example-delay-02.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from Delay.kt by Knit tool. Do not edit.
2 | package kotlinx.coroutines.examples.exampleDelay02
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 | import kotlin.time.Duration.Companion.milliseconds
7 |
8 | fun main() = runBlocking {
9 |
10 | flow {
11 | emit(1)
12 | delay(90)
13 | emit(2)
14 | delay(90)
15 | emit(3)
16 | delay(1010)
17 | emit(4)
18 | delay(1010)
19 | emit(5)
20 | }.debounce {
21 | if (it == 1) {
22 | 0L
23 | } else {
24 | 1000L
25 | }
26 | }
27 | .toList().joinToString().let { println(it) } }
28 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/examples/example-delay-03.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from Delay.kt by Knit tool. Do not edit.
2 | package kotlinx.coroutines.examples.exampleDelay03
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 | import kotlin.time.Duration.Companion.milliseconds
7 |
8 | fun main() = runBlocking {
9 |
10 | flow {
11 | repeat(10) {
12 | emit(it)
13 | delay(110)
14 | }
15 | }.sample(200)
16 | .toList().joinToString().let { println(it) } }
17 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/examples/example-delay-duration-01.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from Delay.kt by Knit tool. Do not edit.
2 | package kotlinx.coroutines.examples.exampleDelayDuration01
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 | import kotlin.time.Duration.Companion.milliseconds
7 |
8 | fun main() = runBlocking {
9 |
10 | flow {
11 | emit(1)
12 | delay(90.milliseconds)
13 | emit(2)
14 | delay(90.milliseconds)
15 | emit(3)
16 | delay(1010.milliseconds)
17 | emit(4)
18 | delay(1010.milliseconds)
19 | emit(5)
20 | }.debounce(1000.milliseconds)
21 | .toList().joinToString().let { println(it) } }
22 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/examples/example-delay-duration-02.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from Delay.kt by Knit tool. Do not edit.
2 | package kotlinx.coroutines.examples.exampleDelayDuration02
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 | import kotlin.time.Duration.Companion.milliseconds
7 |
8 | fun main() = runBlocking {
9 |
10 | flow {
11 | emit(1)
12 | delay(90.milliseconds)
13 | emit(2)
14 | delay(90.milliseconds)
15 | emit(3)
16 | delay(1010.milliseconds)
17 | emit(4)
18 | delay(1010.milliseconds)
19 | emit(5)
20 | }.debounce {
21 | if (it == 1) {
22 | 0.milliseconds
23 | } else {
24 | 1000.milliseconds
25 | }
26 | }
27 | .toList().joinToString().let { println(it) } }
28 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/examples/example-delay-duration-03.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from Delay.kt by Knit tool. Do not edit.
2 | package kotlinx.coroutines.examples.exampleDelayDuration03
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 | import kotlin.time.Duration.Companion.milliseconds
7 |
8 | fun main() = runBlocking {
9 |
10 | flow {
11 | repeat(10) {
12 | emit(it)
13 | delay(110.milliseconds)
14 | }
15 | }.sample(200.milliseconds)
16 | .toList().joinToString().let { println(it) } }
17 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-basic-01.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from coroutines-basics.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleBasic01
3 |
4 | import kotlinx.coroutines.*
5 |
6 | fun main() = runBlocking { // this: CoroutineScope
7 | launch { // launch a new coroutine and continue
8 | delay(1000L) // non-blocking delay for 1 second (default time unit is ms)
9 | println("World!") // print after delay
10 | }
11 | println("Hello") // main coroutine continues while a previous one is delayed
12 | }
13 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-basic-02.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from coroutines-basics.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleBasic02
3 |
4 | import kotlinx.coroutines.*
5 |
6 | fun main() = runBlocking { // this: CoroutineScope
7 | launch { doWorld() }
8 | println("Hello")
9 | }
10 |
11 | // this is your first suspending function
12 | suspend fun doWorld() {
13 | delay(1000L)
14 | println("World!")
15 | }
16 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-basic-03.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from coroutines-basics.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleBasic03
3 |
4 | import kotlinx.coroutines.*
5 |
6 | fun main() = runBlocking {
7 | doWorld()
8 | }
9 |
10 | suspend fun doWorld() = coroutineScope { // this: CoroutineScope
11 | launch {
12 | delay(1000L)
13 | println("World!")
14 | }
15 | println("Hello")
16 | }
17 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-basic-04.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from coroutines-basics.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleBasic04
3 |
4 | import kotlinx.coroutines.*
5 |
6 | // Sequentially executes doWorld followed by "Done"
7 | fun main() = runBlocking {
8 | doWorld()
9 | println("Done")
10 | }
11 |
12 | // Concurrently executes both sections
13 | suspend fun doWorld() = coroutineScope { // this: CoroutineScope
14 | launch {
15 | delay(2000L)
16 | println("World 2")
17 | }
18 | launch {
19 | delay(1000L)
20 | println("World 1")
21 | }
22 | println("Hello")
23 | }
24 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-basic-05.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from coroutines-basics.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleBasic05
3 |
4 | import kotlinx.coroutines.*
5 |
6 | fun main() = runBlocking {
7 | val job = launch { // launch a new coroutine and keep a reference to its Job
8 | delay(1000L)
9 | println("World!")
10 | }
11 | println("Hello")
12 | job.join() // wait until child coroutine completes
13 | println("Done")
14 | }
15 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-basic-06.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from coroutines-basics.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleBasic06
3 |
4 | import kotlinx.coroutines.*
5 |
6 | fun main() = runBlocking {
7 | repeat(50_000) { // launch a lot of coroutines
8 | launch {
9 | delay(5000L)
10 | print(".")
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-cancel-01.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from cancellation-and-timeouts.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleCancel01
3 |
4 | import kotlinx.coroutines.*
5 |
6 | fun main() = runBlocking {
7 | val job = launch {
8 | repeat(1000) { i ->
9 | println("job: I'm sleeping $i ...")
10 | delay(500L)
11 | }
12 | }
13 | delay(1300L) // delay a bit
14 | println("main: I'm tired of waiting!")
15 | job.cancel() // cancels the job
16 | job.join() // waits for job's completion
17 | println("main: Now I can quit.")
18 | }
19 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-cancel-03.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from cancellation-and-timeouts.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleCancel03
3 |
4 | import kotlinx.coroutines.*
5 |
6 | fun main() = runBlocking {
7 | val job = launch(Dispatchers.Default) {
8 | repeat(5) { i ->
9 | try {
10 | // print a message twice a second
11 | println("job: I'm sleeping $i ...")
12 | delay(500)
13 | } catch (e: Exception) {
14 | // log the exception
15 | println(e)
16 | }
17 | }
18 | }
19 | delay(1300L) // delay a bit
20 | println("main: I'm tired of waiting!")
21 | job.cancelAndJoin() // cancels the job and waits for its completion
22 | println("main: Now I can quit.")
23 | }
24 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-cancel-05.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from cancellation-and-timeouts.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleCancel05
3 |
4 | import kotlinx.coroutines.*
5 |
6 | fun main() = runBlocking {
7 | val job = launch {
8 | try {
9 | repeat(1000) { i ->
10 | println("job: I'm sleeping $i ...")
11 | delay(500L)
12 | }
13 | } finally {
14 | println("job: I'm running finally")
15 | }
16 | }
17 | delay(1300L) // delay a bit
18 | println("main: I'm tired of waiting!")
19 | job.cancelAndJoin() // cancels the job and waits for its completion
20 | println("main: Now I can quit.")
21 | }
22 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-cancel-07.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from cancellation-and-timeouts.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleCancel07
3 |
4 | import kotlinx.coroutines.*
5 |
6 | fun main() = runBlocking {
7 | withTimeout(1300L) {
8 | repeat(1000) { i ->
9 | println("I'm sleeping $i ...")
10 | delay(500L)
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-cancel-08.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from cancellation-and-timeouts.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleCancel08
3 |
4 | import kotlinx.coroutines.*
5 |
6 | fun main() = runBlocking {
7 | val result = withTimeoutOrNull(1300L) {
8 | repeat(1000) { i ->
9 | println("I'm sleeping $i ...")
10 | delay(500L)
11 | }
12 | "Done" // will get cancelled before it produces this result
13 | }
14 | println("Result is $result")
15 | }
16 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-channel-01.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from channels.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleChannel01
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.channels.*
6 |
7 | fun main() = runBlocking {
8 | val channel = Channel()
9 | launch {
10 | // this might be heavy CPU-consuming computation or async logic,
11 | // we'll just send five squares
12 | for (x in 1..5) channel.send(x * x)
13 | }
14 | // here we print five received integers:
15 | repeat(5) { println(channel.receive()) }
16 | println("Done!")
17 | }
18 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-channel-02.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from channels.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleChannel02
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.channels.*
6 |
7 | fun main() = runBlocking {
8 | val channel = Channel()
9 | launch {
10 | for (x in 1..5) channel.send(x * x)
11 | channel.close() // we're done sending
12 | }
13 | // here we print received values using `for` loop (until the channel is closed)
14 | for (y in channel) println(y)
15 | println("Done!")
16 | }
17 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-channel-03.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from channels.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleChannel03
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.channels.*
6 |
7 | fun CoroutineScope.produceSquares(): ReceiveChannel = produce {
8 | for (x in 1..5) send(x * x)
9 | }
10 |
11 | fun main() = runBlocking {
12 | val squares = produceSquares()
13 | squares.consumeEach { println(it) }
14 | println("Done!")
15 | }
16 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-channel-05.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from channels.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleChannel05
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.channels.*
6 |
7 | fun main() = runBlocking {
8 | var cur = numbersFrom(2)
9 | repeat(10) {
10 | val prime = cur.receive()
11 | println(prime)
12 | cur = filter(cur, prime)
13 | }
14 | coroutineContext.cancelChildren() // cancel all children to let main finish
15 | }
16 |
17 | fun CoroutineScope.numbersFrom(start: Int) = produce {
18 | var x = start
19 | while (true) send(x++) // infinite stream of integers from start
20 | }
21 |
22 | fun CoroutineScope.filter(numbers: ReceiveChannel, prime: Int) = produce {
23 | for (x in numbers) if (x % prime != 0) send(x)
24 | }
25 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-channel-07.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from channels.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleChannel07
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.channels.*
6 |
7 | fun main() = runBlocking {
8 | val channel = Channel()
9 | launch { sendString(channel, "foo", 200L) }
10 | launch { sendString(channel, "BAR!", 500L) }
11 | repeat(6) { // receive first six
12 | println(channel.receive())
13 | }
14 | coroutineContext.cancelChildren() // cancel all children to let main finish
15 | }
16 |
17 | suspend fun sendString(channel: SendChannel, s: String, time: Long) {
18 | while (true) {
19 | delay(time)
20 | channel.send(s)
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-channel-08.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from channels.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleChannel08
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.channels.*
6 |
7 | fun main() = runBlocking {
8 | val channel = Channel(4) // create buffered channel
9 | val sender = launch { // launch sender coroutine
10 | repeat(10) {
11 | println("Sending $it") // print before sending each element
12 | channel.send(it) // will suspend when buffer is full
13 | }
14 | }
15 | // don't receive anything... just wait....
16 | delay(1000)
17 | sender.cancel() // cancel sender coroutine
18 | }
19 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-compose-01.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from composing-suspending-functions.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleCompose01
3 |
4 | import kotlinx.coroutines.*
5 | import kotlin.system.*
6 |
7 | fun main() = runBlocking {
8 | val time = measureTimeMillis {
9 | val one = doSomethingUsefulOne()
10 | val two = doSomethingUsefulTwo()
11 | println("The answer is ${one + two}")
12 | }
13 | println("Completed in $time ms")
14 | }
15 |
16 | suspend fun doSomethingUsefulOne(): Int {
17 | delay(1000L) // pretend we are doing something useful here
18 | return 13
19 | }
20 |
21 | suspend fun doSomethingUsefulTwo(): Int {
22 | delay(1000L) // pretend we are doing something useful here, too
23 | return 29
24 | }
25 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-compose-02.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from composing-suspending-functions.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleCompose02
3 |
4 | import kotlinx.coroutines.*
5 | import kotlin.system.*
6 |
7 | fun main() = runBlocking {
8 | val time = measureTimeMillis {
9 | val one = async { doSomethingUsefulOne() }
10 | val two = async { doSomethingUsefulTwo() }
11 | println("The answer is ${one.await() + two.await()}")
12 | }
13 | println("Completed in $time ms")
14 | }
15 |
16 | suspend fun doSomethingUsefulOne(): Int {
17 | delay(1000L) // pretend we are doing something useful here
18 | return 13
19 | }
20 |
21 | suspend fun doSomethingUsefulTwo(): Int {
22 | delay(1000L) // pretend we are doing something useful here, too
23 | return 29
24 | }
25 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-context-02.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from coroutine-context-and-dispatchers.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleContext02
3 |
4 | import kotlinx.coroutines.*
5 |
6 | fun main() = runBlocking {
7 | launch(Dispatchers.Unconfined) { // not confined -- will work with main thread
8 | println("Unconfined : I'm working in thread ${Thread.currentThread().name}")
9 | delay(500)
10 | println("Unconfined : After delay in thread ${Thread.currentThread().name}")
11 | }
12 | launch { // context of the parent, main runBlocking coroutine
13 | println("main runBlocking: I'm working in thread ${Thread.currentThread().name}")
14 | delay(1000)
15 | println("main runBlocking: After delay in thread ${Thread.currentThread().name}")
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-context-03.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from coroutine-context-and-dispatchers.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleContext03
3 |
4 | import kotlinx.coroutines.*
5 |
6 | fun log(msg: String) = println("[${Thread.currentThread().name}] $msg")
7 |
8 | fun main() = runBlocking {
9 | val a = async {
10 | log("I'm computing a piece of the answer")
11 | 6
12 | }
13 | val b = async {
14 | log("I'm computing another piece of the answer")
15 | 7
16 | }
17 | log("The answer is ${a.await() * b.await()}")
18 | }
19 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-context-04.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from coroutine-context-and-dispatchers.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleContext04
3 |
4 | import kotlinx.coroutines.*
5 |
6 | fun log(msg: String) = println("[${Thread.currentThread().name}] $msg")
7 |
8 | fun main() {
9 | newSingleThreadContext("Ctx1").use { ctx1 ->
10 | newSingleThreadContext("Ctx2").use { ctx2 ->
11 | runBlocking(ctx1) {
12 | log("Started in ctx1")
13 | withContext(ctx2) {
14 | log("Working in ctx2")
15 | }
16 | log("Back to ctx1")
17 | }
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-context-05.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from coroutine-context-and-dispatchers.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleContext05
3 |
4 | import kotlinx.coroutines.*
5 |
6 | fun main() = runBlocking {
7 | println("My job is ${coroutineContext[Job]}")
8 | }
9 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-context-07.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from coroutine-context-and-dispatchers.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleContext07
3 |
4 | import kotlinx.coroutines.*
5 |
6 | fun main() = runBlocking {
7 | // launch a coroutine to process some kind of incoming request
8 | val request = launch {
9 | repeat(3) { i -> // launch a few children jobs
10 | launch {
11 | delay((i + 1) * 200L) // variable delay 200ms, 400ms, 600ms
12 | println("Coroutine $i is done")
13 | }
14 | }
15 | println("request: I'm done and I don't explicitly join my children that are still active")
16 | }
17 | request.join() // wait for completion of the request, including all its children
18 | println("Now processing of the request is complete")
19 | }
20 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-context-08.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from coroutine-context-and-dispatchers.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleContext08
3 |
4 | import kotlinx.coroutines.*
5 |
6 | fun log(msg: String) = println("[${Thread.currentThread().name}] $msg")
7 |
8 | fun main() = runBlocking(CoroutineName("main")) {
9 | log("Started main coroutine")
10 | // run two background value computations
11 | val v1 = async(CoroutineName("v1coroutine")) {
12 | delay(500)
13 | log("Computing v1")
14 | 6
15 | }
16 | val v2 = async(CoroutineName("v2coroutine")) {
17 | delay(1000)
18 | log("Computing v2")
19 | 7
20 | }
21 | log("The answer for v1 * v2 = ${v1.await() * v2.await()}")
22 | }
23 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-context-09.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from coroutine-context-and-dispatchers.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleContext09
3 |
4 | import kotlinx.coroutines.*
5 |
6 | fun main() = runBlocking {
7 | launch(Dispatchers.Default + CoroutineName("test")) {
8 | println("I'm working in thread ${Thread.currentThread().name}")
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-exceptions-02.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from exception-handling.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleExceptions02
3 |
4 | import kotlinx.coroutines.*
5 |
6 | @OptIn(DelicateCoroutinesApi::class)
7 | fun main() = runBlocking {
8 | val handler = CoroutineExceptionHandler { _, exception ->
9 | println("CoroutineExceptionHandler got $exception")
10 | }
11 | val job = GlobalScope.launch(handler) { // root coroutine, running in GlobalScope
12 | throw AssertionError()
13 | }
14 | val deferred = GlobalScope.async(handler) { // also root, but async instead of launch
15 | throw ArithmeticException() // Nothing will be printed, relying on user to call deferred.await()
16 | }
17 | joinAll(job, deferred)
18 | }
19 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-exceptions-03.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from exception-handling.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleExceptions03
3 |
4 | import kotlinx.coroutines.*
5 |
6 | fun main() = runBlocking {
7 | val job = launch {
8 | val child = launch {
9 | try {
10 | delay(Long.MAX_VALUE)
11 | } finally {
12 | println("Child is cancelled")
13 | }
14 | }
15 | yield()
16 | println("Cancelling child")
17 | child.cancel()
18 | child.join()
19 | yield()
20 | println("Parent is not cancelled")
21 | }
22 | job.join()
23 | }
24 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-01.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow01
3 |
4 | fun simple(): List = listOf(1, 2, 3)
5 |
6 | fun main() {
7 | simple().forEach { value -> println(value) }
8 | }
9 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-02.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow02
3 |
4 | fun simple(): Sequence = sequence { // sequence builder
5 | for (i in 1..3) {
6 | Thread.sleep(100) // pretend we are computing it
7 | yield(i) // yield next value
8 | }
9 | }
10 |
11 | fun main() {
12 | simple().forEach { value -> println(value) }
13 | }
14 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-03.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow03
3 |
4 | import kotlinx.coroutines.*
5 |
6 | suspend fun simple(): List {
7 | delay(1000) // pretend we are doing something asynchronous here
8 | return listOf(1, 2, 3)
9 | }
10 |
11 | fun main() = runBlocking {
12 | simple().forEach { value -> println(value) }
13 | }
14 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-04.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow04
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun simple(): Flow = flow { // flow builder
8 | for (i in 1..3) {
9 | delay(100) // pretend we are doing something useful here
10 | emit(i) // emit next value
11 | }
12 | }
13 |
14 | fun main() = runBlocking {
15 | // Launch a concurrent coroutine to check if the main thread is blocked
16 | launch {
17 | for (k in 1..3) {
18 | println("I'm not blocked $k")
19 | delay(100)
20 | }
21 | }
22 | // Collect the flow
23 | simple().collect { value -> println(value) }
24 | }
25 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-05.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow05
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun simple(): Flow = flow {
8 | println("Flow started")
9 | for (i in 1..3) {
10 | delay(100)
11 | emit(i)
12 | }
13 | }
14 |
15 | fun main() = runBlocking {
16 | println("Calling simple function...")
17 | val flow = simple()
18 | println("Calling collect...")
19 | flow.collect { value -> println(value) }
20 | println("Calling collect again...")
21 | flow.collect { value -> println(value) }
22 | }
23 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-06.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow06
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun simple(): Flow = flow {
8 | for (i in 1..3) {
9 | delay(100)
10 | println("Emitting $i")
11 | emit(i)
12 | }
13 | }
14 |
15 | fun main() = runBlocking {
16 | withTimeoutOrNull(250) { // Timeout after 250ms
17 | simple().collect { value -> println(value) }
18 | }
19 | println("Done")
20 | }
21 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-07.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow07
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun main() = runBlocking {
8 | // Convert an integer range to a flow
9 | (1..3).asFlow().collect { value -> println(value) }
10 | }
11 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-08.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow08
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | suspend fun performRequest(request: Int): String {
8 | delay(1000) // imitate long-running asynchronous work
9 | return "response $request"
10 | }
11 |
12 | fun main() = runBlocking {
13 | (1..3).asFlow() // a flow of requests
14 | .map { request -> performRequest(request) }
15 | .collect { response -> println(response) }
16 | }
17 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-09.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow09
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | suspend fun performRequest(request: Int): String {
8 | delay(1000) // imitate long-running asynchronous work
9 | return "response $request"
10 | }
11 |
12 | fun main() = runBlocking {
13 | (1..3).asFlow() // a flow of requests
14 | .transform { request ->
15 | emit("Making request $request")
16 | emit(performRequest(request))
17 | }
18 | .collect { response -> println(response) }
19 | }
20 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-10.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow10
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun numbers(): Flow = flow {
8 | try {
9 | emit(1)
10 | emit(2)
11 | println("This line will not execute")
12 | emit(3)
13 | } finally {
14 | println("Finally in numbers")
15 | }
16 | }
17 |
18 | fun main() = runBlocking {
19 | numbers()
20 | .take(2) // take only the first two
21 | .collect { value -> println(value) }
22 | }
23 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-11.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow11
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun main() = runBlocking {
8 | val sum = (1..5).asFlow()
9 | .map { it * it } // squares of numbers from 1 to 5
10 | .reduce { a, b -> a + b } // sum them (terminal operator)
11 | println(sum)
12 | }
13 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-12.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow12
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun main() = runBlocking {
8 | (1..5).asFlow()
9 | .filter {
10 | println("Filter $it")
11 | it % 2 == 0
12 | }
13 | .map {
14 | println("Map $it")
15 | "string $it"
16 | }.collect {
17 | println("Collect $it")
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-13.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow13
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun log(msg: String) = println("[${Thread.currentThread().name}] $msg")
8 |
9 | fun simple(): Flow = flow {
10 | log("Started simple flow")
11 | for (i in 1..3) {
12 | emit(i)
13 | }
14 | }
15 |
16 | fun main() = runBlocking {
17 | simple().collect { value -> log("Collected $value") }
18 | }
19 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-14.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow14
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun simple(): Flow = flow {
8 | // The WRONG way to change context for CPU-consuming code in flow builder
9 | kotlinx.coroutines.withContext(Dispatchers.Default) {
10 | for (i in 1..3) {
11 | Thread.sleep(100) // pretend we are computing it in CPU-consuming way
12 | emit(i) // emit next value
13 | }
14 | }
15 | }
16 |
17 | fun main() = runBlocking {
18 | simple().collect { value -> println(value) }
19 | }
20 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-15.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow15
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun log(msg: String) = println("[${Thread.currentThread().name}] $msg")
8 |
9 | fun simple(): Flow = flow {
10 | for (i in 1..3) {
11 | Thread.sleep(100) // pretend we are computing it in CPU-consuming way
12 | log("Emitting $i")
13 | emit(i) // emit next value
14 | }
15 | }.flowOn(Dispatchers.Default) // RIGHT way to change context for CPU-consuming code in flow builder
16 |
17 | fun main() = runBlocking {
18 | simple().collect { value ->
19 | log("Collected $value")
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-16.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow16
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 | import kotlin.system.*
7 |
8 | fun simple(): Flow = flow {
9 | for (i in 1..3) {
10 | delay(100) // pretend we are asynchronously waiting 100 ms
11 | emit(i) // emit next value
12 | }
13 | }
14 |
15 | fun main() = runBlocking {
16 | val time = measureTimeMillis {
17 | simple().collect { value ->
18 | delay(300) // pretend we are processing it for 300 ms
19 | println(value)
20 | }
21 | }
22 | println("Collected in $time ms")
23 | }
24 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-17.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow17
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 | import kotlin.system.*
7 |
8 | fun simple(): Flow = flow {
9 | for (i in 1..3) {
10 | delay(100) // pretend we are asynchronously waiting 100 ms
11 | emit(i) // emit next value
12 | }
13 | }
14 |
15 | fun main() = runBlocking {
16 | val time = measureTimeMillis {
17 | simple()
18 | .buffer() // buffer emissions, don't wait
19 | .collect { value ->
20 | delay(300) // pretend we are processing it for 300 ms
21 | println(value)
22 | }
23 | }
24 | println("Collected in $time ms")
25 | }
26 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-18.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow18
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 | import kotlin.system.*
7 |
8 | fun simple(): Flow = flow {
9 | for (i in 1..3) {
10 | delay(100) // pretend we are asynchronously waiting 100 ms
11 | emit(i) // emit next value
12 | }
13 | }
14 |
15 | fun main() = runBlocking {
16 | val time = measureTimeMillis {
17 | simple()
18 | .conflate() // conflate emissions, don't process each one
19 | .collect { value ->
20 | delay(300) // pretend we are processing it for 300 ms
21 | println(value)
22 | }
23 | }
24 | println("Collected in $time ms")
25 | }
26 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-19.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow19
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 | import kotlin.system.*
7 |
8 | fun simple(): Flow = flow {
9 | for (i in 1..3) {
10 | delay(100) // pretend we are asynchronously waiting 100 ms
11 | emit(i) // emit next value
12 | }
13 | }
14 |
15 | fun main() = runBlocking {
16 | val time = measureTimeMillis {
17 | simple()
18 | .collectLatest { value -> // cancel & restart on the latest value
19 | println("Collecting $value")
20 | delay(300) // pretend we are processing it for 300 ms
21 | println("Done $value")
22 | }
23 | }
24 | println("Collected in $time ms")
25 | }
26 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-20.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow20
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun main() = runBlocking {
8 | val nums = (1..3).asFlow() // numbers 1..3
9 | val strs = flowOf("one", "two", "three") // strings
10 | nums.zip(strs) { a, b -> "$a -> $b" } // compose a single string
11 | .collect { println(it) } // collect and print
12 | }
13 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-21.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow21
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun main() = runBlocking {
8 | val nums = (1..3).asFlow().onEach { delay(300) } // numbers 1..3 every 300 ms
9 | val strs = flowOf("one", "two", "three").onEach { delay(400) } // strings every 400 ms
10 | val startTime = currentTimeMillis() // remember the start time
11 | nums.zip(strs) { a, b -> "$a -> $b" } // compose a single string with "zip"
12 | .collect { value -> // collect and print
13 | println("$value at ${currentTimeMillis() - startTime} ms from start")
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-22.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow22
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun main() = runBlocking {
8 | val nums = (1..3).asFlow().onEach { delay(300) } // numbers 1..3 every 300 ms
9 | val strs = flowOf("one", "two", "three").onEach { delay(400) } // strings every 400 ms
10 | val startTime = currentTimeMillis() // remember the start time
11 | nums.combine(strs) { a, b -> "$a -> $b" } // compose a single string with "combine"
12 | .collect { value -> // collect and print
13 | println("$value at ${currentTimeMillis() - startTime} ms from start")
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-23.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow23
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun requestFlow(i: Int): Flow = flow {
8 | emit("$i: First")
9 | delay(500) // wait 500 ms
10 | emit("$i: Second")
11 | }
12 |
13 | fun main() = runBlocking {
14 | val startTime = currentTimeMillis() // remember the start time
15 | (1..3).asFlow().onEach { delay(100) } // emit a number every 100 ms
16 | .flatMapConcat { requestFlow(it) }
17 | .collect { value -> // collect and print
18 | println("$value at ${currentTimeMillis() - startTime} ms from start")
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-24.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow24
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun requestFlow(i: Int): Flow = flow {
8 | emit("$i: First")
9 | delay(500) // wait 500 ms
10 | emit("$i: Second")
11 | }
12 |
13 | fun main() = runBlocking {
14 | val startTime = currentTimeMillis() // remember the start time
15 | (1..3).asFlow().onEach { delay(100) } // a number every 100 ms
16 | .flatMapMerge { requestFlow(it) }
17 | .collect { value -> // collect and print
18 | println("$value at ${currentTimeMillis() - startTime} ms from start")
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-25.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow25
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun requestFlow(i: Int): Flow = flow {
8 | emit("$i: First")
9 | delay(500) // wait 500 ms
10 | emit("$i: Second")
11 | }
12 |
13 | fun main() = runBlocking {
14 | val startTime = currentTimeMillis() // remember the start time
15 | (1..3).asFlow().onEach { delay(100) } // a number every 100 ms
16 | .flatMapLatest { requestFlow(it) }
17 | .collect { value -> // collect and print
18 | println("$value at ${currentTimeMillis() - startTime} ms from start")
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-26.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow26
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun simple(): Flow = flow {
8 | for (i in 1..3) {
9 | println("Emitting $i")
10 | emit(i) // emit next value
11 | }
12 | }
13 |
14 | fun main() = runBlocking {
15 | try {
16 | simple().collect { value ->
17 | println(value)
18 | check(value <= 1) { "Collected $value" }
19 | }
20 | } catch (e: Throwable) {
21 | println("Caught $e")
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-27.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow27
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun simple(): Flow =
8 | flow {
9 | for (i in 1..3) {
10 | println("Emitting $i")
11 | emit(i) // emit next value
12 | }
13 | }
14 | .map { value ->
15 | check(value <= 1) { "Crashed on $value" }
16 | "string $value"
17 | }
18 |
19 | fun main() = runBlocking {
20 | try {
21 | simple().collect { value -> println(value) }
22 | } catch (e: Throwable) {
23 | println("Caught $e")
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-28.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow28
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun simple(): Flow =
8 | flow {
9 | for (i in 1..3) {
10 | println("Emitting $i")
11 | emit(i) // emit next value
12 | }
13 | }
14 | .map { value ->
15 | check(value <= 1) { "Crashed on $value" }
16 | "string $value"
17 | }
18 |
19 | fun main() = runBlocking {
20 | simple()
21 | .catch { e -> emit("Caught $e") } // emit on exception
22 | .collect { value -> println(value) }
23 | }
24 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-29.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow29
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun simple(): Flow = flow {
8 | for (i in 1..3) {
9 | println("Emitting $i")
10 | emit(i)
11 | }
12 | }
13 |
14 | fun main() = runBlocking {
15 | simple()
16 | .catch { e -> println("Caught $e") } // does not catch downstream exceptions
17 | .collect { value ->
18 | check(value <= 1) { "Collected $value" }
19 | println(value)
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-30.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow30
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun simple(): Flow = flow {
8 | for (i in 1..3) {
9 | println("Emitting $i")
10 | emit(i)
11 | }
12 | }
13 |
14 | fun main() = runBlocking {
15 | simple()
16 | .onEach { value ->
17 | check(value <= 1) { "Collected $value" }
18 | println(value)
19 | }
20 | .catch { e -> println("Caught $e") }
21 | .collect()
22 | }
23 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-31.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow31
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun simple(): Flow = (1..3).asFlow()
8 |
9 | fun main() = runBlocking {
10 | try {
11 | simple().collect { value -> println(value) }
12 | } finally {
13 | println("Done")
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-32.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow32
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun simple(): Flow = (1..3).asFlow()
8 |
9 | fun main() = runBlocking {
10 | simple()
11 | .onCompletion { println("Done") }
12 | .collect { value -> println(value) }
13 | }
14 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-33.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow33
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun simple(): Flow = flow {
8 | emit(1)
9 | throw RuntimeException()
10 | }
11 |
12 | fun main() = runBlocking {
13 | simple()
14 | .onCompletion { cause -> if (cause != null) println("Flow completed exceptionally") }
15 | .catch { cause -> println("Caught exception") }
16 | .collect { value -> println(value) }
17 | }
18 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-34.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow34
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun simple(): Flow = (1..3).asFlow()
8 |
9 | fun main() = runBlocking {
10 | simple()
11 | .onCompletion { cause -> println("Flow completed with $cause") }
12 | .collect { value ->
13 | check(value <= 1) { "Collected $value" }
14 | println(value)
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-35.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow35
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | // Imitate a flow of events
8 | fun events(): Flow = (1..3).asFlow().onEach { delay(100) }
9 |
10 | fun main() = runBlocking {
11 | events()
12 | .onEach { event -> println("Event: $event") }
13 | .collect() // <--- Collecting the flow waits
14 | println("Done")
15 | }
16 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-36.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow36
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | // Imitate a flow of events
8 | fun events(): Flow = (1..3).asFlow().onEach { delay(100) }
9 |
10 | fun main() = runBlocking {
11 | events()
12 | .onEach { event -> println("Event: $event") }
13 | .launchIn(this) // <--- Launching the flow in a separate coroutine
14 | println("Done")
15 | }
16 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-37.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow37
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun foo(): Flow = flow {
8 | for (i in 1..5) {
9 | println("Emitting $i")
10 | emit(i)
11 | }
12 | }
13 |
14 | fun main() = runBlocking {
15 | foo().collect { value ->
16 | if (value == 3) cancel()
17 | println(value)
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-38.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow38
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun main() = runBlocking {
8 | (1..5).asFlow().collect { value ->
9 | if (value == 3) cancel()
10 | println(value)
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-flow-39.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from flow.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleFlow39
3 |
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 |
7 | fun main() = runBlocking {
8 | (1..5).asFlow().cancellable().collect { value ->
9 | if (value == 3) cancel()
10 | println(value)
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/guide/example-supervision-03.kt:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from exception-handling.md by Knit tool. Do not edit.
2 | package kotlinx.coroutines.guide.exampleSupervision03
3 |
4 | import kotlin.coroutines.*
5 | import kotlinx.coroutines.*
6 |
7 | fun main() = runBlocking {
8 | val handler = CoroutineExceptionHandler { _, exception ->
9 | println("CoroutineExceptionHandler got $exception")
10 | }
11 | supervisorScope {
12 | val child = launch(handler) {
13 | println("The child throws an exception")
14 | throw AssertionError()
15 | }
16 | println("The scope is completing")
17 | }
18 | println("The scope is completed")
19 | }
20 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/internal/FastServiceLoaderTest.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | import kotlinx.coroutines.testing.*
4 | import kotlinx.coroutines.*
5 | import kotlin.test.*
6 |
7 | class FastServiceLoaderTest : TestBase() {
8 | @Test
9 | fun testCrossModuleService() {
10 | val providers = CoroutineScope::class.java.let { FastServiceLoader.loadProviders(it, it.classLoader) }
11 | assertEquals(3, providers.size)
12 | val className = "kotlinx.coroutines.android.EmptyCoroutineScopeImpl"
13 | for (i in 1 .. 3) {
14 | assert(providers[i - 1].javaClass.name == "$className$i")
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/lincheck/ResizableAtomicArrayLincheckTest.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.lincheck
2 |
3 | import kotlinx.coroutines.*
4 | import kotlinx.coroutines.internal.*
5 | import org.jetbrains.kotlinx.lincheck.annotations.*
6 | import org.jetbrains.kotlinx.lincheck.paramgen.*
7 |
8 | @Param(name = "index", gen = IntGen::class, conf = "0:4")
9 | @Param(name = "value", gen = IntGen::class, conf = "1:5")
10 | class ResizableAtomicArrayLincheckTest : AbstractLincheckTest() {
11 | private val a = ResizableAtomicArray(2)
12 |
13 | @Operation
14 | fun get(@Param(name = "index") index: Int): Int? = a[index]
15 |
16 | @Operation(nonParallelGroup = "writer")
17 | fun set(@Param(name = "index") index: Int, @Param(name = "value") value: Int) {
18 | a.setSynchronized(index, value)
19 | }
20 | }
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/jvm/test/scheduling/TestTimeSource.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.scheduling
2 |
3 |
4 | internal class TestTimeSource(var time: Long) : SchedulerTimeSource() {
5 |
6 | override fun nanoTime() = time
7 |
8 | fun step(delta: Long = WORK_STEALING_TIME_RESOLUTION_NS) {
9 | time += delta
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/knit.properties:
--------------------------------------------------------------------------------
1 | knit.package=kotlinx.coroutines.examples
2 | knit.dir=jvm/test/examples/
3 |
4 | test.package=kotlinx.coroutines.examples.test
5 | test.dir=jvm/test/examples/test/
6 |
7 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/native/src/CloseableCoroutineDispatcher.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | public actual abstract class CloseableCoroutineDispatcher actual constructor() : CoroutineDispatcher(), AutoCloseable {
4 | public actual abstract override fun close()
5 | }
6 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/native/src/Debug.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | import kotlin.math.*
4 | import kotlin.native.*
5 |
6 | internal actual val DEBUG: Boolean = false
7 |
8 | internal actual val Any.hexAddress: String get() = identityHashCode().toUInt().toString(16)
9 |
10 | internal actual val Any.classSimpleName: String get() = this::class.simpleName ?: "Unknown"
11 |
12 | internal actual inline fun assert(value: () -> Boolean) {}
13 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/native/src/Runnable.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | /**
4 | * A runnable task for [CoroutineDispatcher.dispatch].
5 | *
6 | * Equivalent to the type `() -> Unit`.
7 | */
8 | public actual fun interface Runnable {
9 | /**
10 | * @suppress
11 | */
12 | public actual fun run()
13 | }
14 |
15 | @Deprecated(
16 | "Preserved for binary compatibility, see https://github.com/Kotlin/kotlinx.coroutines/issues/4309",
17 | level = DeprecationLevel.HIDDEN
18 | )
19 | public inline fun Runnable(crossinline block: () -> Unit): Runnable =
20 | object : Runnable {
21 | override fun run() {
22 | block()
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/native/src/SchedulerTask.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | internal actual abstract class SchedulerTask : Runnable
4 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/native/src/flow/internal/FlowExceptions.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.flow.internal
2 |
3 | import kotlinx.coroutines.*
4 | import kotlinx.coroutines.flow.*
5 |
6 | internal actual class AbortFlowException actual constructor(
7 | actual val owner: Any
8 | ) : CancellationException("Flow was aborted, no more elements needed")
9 | internal actual class ChildCancelledException : CancellationException("Child of the scoped flow was cancelled")
10 |
11 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/native/src/internal/LocalAtomics.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | import kotlinx.atomicfu.*
4 |
5 | internal actual class LocalAtomicInt actual constructor(value: Int) {
6 |
7 | private val iRef = atomic(value)
8 |
9 | actual fun set(value: Int) {
10 | iRef.value = value
11 | }
12 |
13 | actual fun get(): Int = iRef.value
14 |
15 | actual fun decrementAndGet(): Int = iRef.decrementAndGet()
16 | }
17 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/native/src/internal/ProbesSupport.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | import kotlin.coroutines.*
4 |
5 | @Suppress("NOTHING_TO_INLINE")
6 | internal actual inline fun probeCoroutineCreated(completion: Continuation): Continuation = completion
7 |
8 | @Suppress("NOTHING_TO_INLINE")
9 | internal actual inline fun probeCoroutineResumed(completion: Continuation) { }
10 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/native/src/internal/StackTraceRecovery.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | import kotlin.coroutines.*
4 |
5 | internal actual fun recoverStackTrace(exception: E, continuation: Continuation<*>): E = exception
6 | internal actual fun recoverStackTrace(exception: E): E = exception
7 |
8 | @PublishedApi
9 | internal actual fun unwrap(exception: E): E = exception
10 | internal actual suspend inline fun recoverAndThrow(exception: Throwable): Nothing = throw exception
11 |
12 | @Suppress("UNUSED")
13 | internal actual interface CoroutineStackFrame {
14 | public actual val callerFrame: CoroutineStackFrame?
15 | public actual fun getStackTraceElement(): StackTraceElement?
16 | }
17 |
18 | internal actual typealias StackTraceElement = Any
19 |
20 | internal actual fun Throwable.initCause(cause: Throwable) {
21 | }
22 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/native/src/internal/Synchronized.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | import kotlinx.cinterop.*
4 | import kotlinx.coroutines.*
5 | import kotlinx.atomicfu.locks.withLock as withLock2
6 |
7 | /**
8 | * @suppress **This an internal API and should not be used from general code.**
9 | */
10 | @InternalCoroutinesApi
11 | public actual typealias SynchronizedObject = kotlinx.atomicfu.locks.SynchronizedObject
12 |
13 | /**
14 | * @suppress **This an internal API and should not be used from general code.**
15 | */
16 | @InternalCoroutinesApi
17 | public actual inline fun synchronizedImpl(lock: SynchronizedObject, block: () -> T): T = lock.withLock2(block)
18 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/native/src/internal/SystemProps.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | internal actual fun systemProp(propertyName: String): String? = null
4 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/native/src/internal/ThreadContext.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | import kotlin.coroutines.*
4 |
5 | internal actual fun threadContextElements(context: CoroutineContext): Any = 0
6 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/native/src/internal/ThreadLocal.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | import kotlin.native.concurrent.ThreadLocal
4 |
5 | internal actual class CommonThreadLocal(private val name: Symbol) {
6 | @Suppress("UNCHECKED_CAST")
7 | actual fun get(): T = Storage[name] as T
8 | actual fun set(value: T) { Storage[name] = value }
9 | }
10 |
11 | internal actual fun commonThreadLocal(name: Symbol): CommonThreadLocal = CommonThreadLocal(name)
12 |
13 | @ThreadLocal
14 | private object Storage: MutableMap by mutableMapOf()
15 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/native/test/ConcurrentTestUtilities.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.exceptions
2 |
3 | import platform.posix.*
4 | import kotlin.native.concurrent.*
5 |
6 | actual inline fun yieldThread() { sched_yield() }
7 |
8 | actual fun currentThreadName(): String = Worker.current.name
9 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/native/test/DelayExceptionTest.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | import kotlinx.coroutines.testing.*
4 | import kotlin.coroutines.*
5 | import kotlin.test.*
6 |
7 | class DelayExceptionTest : TestBase() {
8 |
9 | @Test
10 | fun testMaxDelay() = runBlocking {
11 | expect(1)
12 | val job = launch {
13 | expect(2)
14 | delay(Long.MAX_VALUE)
15 | }
16 | yield()
17 | job.cancel()
18 | finish(3)
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/nativeDarwin/test/Launcher.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | import platform.CoreFoundation.*
4 | import kotlin.native.concurrent.*
5 | import kotlin.native.internal.test.*
6 | import kotlin.system.*
7 |
8 | // This is a separate entry point for tests in background
9 | fun mainBackground(args: Array) {
10 | val worker = Worker.start(name = "main-background")
11 | worker.execute(TransferMode.SAFE, { args }) {
12 | val result = testLauncherEntryPoint(it)
13 | exitProcess(result)
14 | }
15 | CFRunLoopRun()
16 | error("CFRunLoopRun should never return")
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/nativeDarwin/test/MainDispatcherTest.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | import kotlinx.coroutines.testing.*
4 | import kotlinx.cinterop.*
5 | import kotlinx.coroutines.testing.*
6 | import platform.CoreFoundation.*
7 | import platform.darwin.*
8 | import kotlin.coroutines.*
9 | import kotlin.test.*
10 |
11 | class MainDispatcherTest : MainDispatcherTestBase.WithRealTimeDelay() {
12 |
13 | override fun isMainThread(): Boolean = CFRunLoopGetCurrent() == CFRunLoopGetMain()
14 |
15 | // skip if already on the main thread, run blocking doesn't really work well with that
16 | override fun shouldSkipTesting(): Boolean = isMainThread()
17 |
18 | override fun scheduleOnMainQueue(block: () -> Unit) {
19 | autoreleasepool {
20 | dispatch_async(dispatch_get_main_queue()) {
21 | block()
22 | }
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/nativeOther/test/Launcher.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | import kotlin.native.concurrent.*
4 | import kotlin.native.internal.test.*
5 | import kotlin.system.*
6 |
7 | // This is a separate entry point for tests in background
8 | fun mainBackground(args: Array) {
9 | val worker = Worker.start(name = "main-background")
10 | worker.execute(TransferMode.SAFE, { args }) {
11 | val result = testLauncherEntryPoint(it)
12 | exitProcess(result)
13 | }.result // block main thread
14 | }
15 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/wasmJs/src/CoroutineContext.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | internal external interface JsProcess : JsAny {
4 | fun nextTick(handler: () -> Unit)
5 | }
6 |
7 | internal fun tryGetProcess(): JsProcess? =
8 | js("(typeof(process) !== 'undefined' && typeof(process.nextTick) === 'function') ? process : null")
9 |
10 | internal fun tryGetWindow(): W3CWindow? =
11 | js("(typeof(window) !== 'undefined' && window != null && typeof(window.addEventListener) === 'function') ? window : null")
12 |
13 | internal actual fun createDefaultDispatcher(): CoroutineDispatcher =
14 | tryGetProcess()?.let(::NodeDispatcher)
15 | ?: tryGetWindow()?.let(::WindowDispatcher)
16 | ?: SetTimeoutDispatcher
17 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/wasmJs/src/Debug.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | internal actual val DEBUG: Boolean = false
4 |
5 | internal actual val Any.hexAddress: String
6 | get() = this.hashCode().toString()
7 |
8 | internal actual val Any.classSimpleName: String get() = this::class.simpleName ?: "Unknown"
9 |
10 | internal actual inline fun assert(value: () -> Boolean) {}
11 |
12 | internal external interface Console {
13 | fun error(s: String)
14 | }
15 |
16 | internal external val console: Console
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/wasmJs/src/internal/CoroutineExceptionHandlerImpl.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | import kotlinx.coroutines.*
4 |
5 | internal actual fun propagateExceptionFinalResort(exception: Throwable) {
6 | // log exception
7 | console.error(exception.toString())
8 | }
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/wasmWasi/src/Debug.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines
2 |
3 | internal actual val DEBUG: Boolean = false
4 |
5 | internal actual val Any.hexAddress: String
6 | get() = this.hashCode().toString()
7 |
8 | internal actual val Any.classSimpleName: String get() = this::class.simpleName ?: "Unknown"
9 |
10 | internal actual inline fun assert(value: () -> Boolean) {}
--------------------------------------------------------------------------------
/kotlinx-coroutines-core/wasmWasi/src/internal/CoroutineRunner.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.internal
2 |
3 | import kotlinx.coroutines.*
4 | import kotlin.coroutines.*
5 |
6 | /** @suppress **This is internal API and it is subject to change.** */
7 | @InternalCoroutinesApi
8 | public fun runTestCoroutine(context: CoroutineContext, block: suspend CoroutineScope.() -> Unit) {
9 | val newContext = GlobalScope.newCoroutineContext(context)
10 | val coroutine = object: AbstractCoroutine(newContext, initParentJob = true, active = true) {}
11 | coroutine.start(CoroutineStart.DEFAULT, coroutine, block)
12 | runEventLoop()
13 | check(coroutine.isCompleted) { "Coroutine $coroutine did not complete, but the system reached quiescence" }
14 | coroutine.getCompletionExceptionOrNull()?.let { throw it }
15 | }
16 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-debug/resources/META-INF/services/reactor.blockhound.integration.BlockHoundIntegration:
--------------------------------------------------------------------------------
1 | kotlinx.coroutines.debug.CoroutinesBlockHoundIntegration
--------------------------------------------------------------------------------
/kotlinx-coroutines-debug/src/NoOpProbes.kt:
--------------------------------------------------------------------------------
1 | @file:Suppress("unused", "UNUSED_PARAMETER")
2 |
3 | package kotlinx.coroutines.debug
4 |
5 | import kotlin.coroutines.*
6 |
7 | /*
8 | * Empty class used to replace installed agent in the end of debug session
9 | */
10 | @JvmName("probeCoroutineResumed")
11 | internal fun probeCoroutineResumedNoOp(frame: Continuation<*>) = Unit
12 | @JvmName("probeCoroutineSuspended")
13 | internal fun probeCoroutineSuspendedNoOp(frame: Continuation<*>) = Unit
14 | @JvmName("probeCoroutineCreated")
15 | internal fun probeCoroutineCreatedNoOp(completion: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation = completion
16 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-debug/src/module-info.java:
--------------------------------------------------------------------------------
1 | module kotlinx.coroutines.debug {
2 | requires java.management;
3 | requires java.instrument;
4 | requires kotlin.stdlib;
5 | requires kotlinx.coroutines.core;
6 | requires static net.bytebuddy;
7 | requires static net.bytebuddy.agent;
8 | requires static org.junit.jupiter.api;
9 | requires static org.junit.platform.commons;
10 |
11 | exports kotlinx.coroutines.debug;
12 | exports kotlinx.coroutines.debug.junit4;
13 | exports kotlinx.coroutines.debug.junit5;
14 | }
15 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-debug/test/DebugTestBase.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.debug
2 |
3 |
4 | import kotlinx.coroutines.testing.*
5 | import kotlinx.coroutines.*
6 | import kotlinx.coroutines.debug.junit4.*
7 | import org.junit.*
8 |
9 | open class DebugTestBase : TestBase() {
10 |
11 | @JvmField
12 | @Rule
13 | val timeout = CoroutinesTimeout.seconds(60)
14 |
15 | @Before
16 | open fun setUp() {
17 | DebugProbes.sanitizeStackTraces = false
18 | DebugProbes.enableCreationStackTraces = false
19 | DebugProbes.install()
20 | }
21 |
22 | @After
23 | fun tearDown() {
24 | DebugProbes.uninstall()
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-debug/test/LazyCoroutineTest.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.debug
2 |
3 | import kotlinx.coroutines.testing.*
4 | import kotlinx.coroutines.*
5 | import org.junit.Test
6 | import kotlin.test.*
7 |
8 | class LazyCoroutineTest : DebugTestBase() {
9 |
10 | @Test
11 | fun testLazyCompletedCoroutine() = runTest {
12 | val job = launch(start = CoroutineStart.LAZY) {}
13 | job.invokeOnCompletion { expect(2) }
14 | expect(1)
15 | job.cancelAndJoin()
16 | expect(3)
17 | assertEquals(1, DebugProbes.dumpCoroutinesInfo().size) // Outer runBlocking
18 | verifyPartialDump(1, "BlockingCoroutine{Active}")
19 | finish(4)
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-debug/test/RecoveryExample.kt:
--------------------------------------------------------------------------------
1 | @file:Suppress("PackageDirectoryMismatch")
2 | package example
3 |
4 | import kotlinx.coroutines.*
5 |
6 | object PublicApiImplementation : CoroutineScope by CoroutineScope(CoroutineName("Example")) {
7 |
8 | private fun doWork(): Int {
9 | error("Internal invariant failed")
10 | }
11 |
12 | private fun asynchronousWork(): Int {
13 | return doWork() + 1
14 | }
15 |
16 | public suspend fun awaitAsynchronousWorkInMainThread() {
17 | val task = async(Dispatchers.Default) {
18 | asynchronousWork()
19 | }
20 |
21 | task.await()
22 | }
23 | }
24 |
25 | suspend fun main() {
26 | // Try to switch debug mode on and off to see the difference
27 | PublicApiImplementation.awaitAsynchronousWorkInMainThread()
28 | }
29 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-debug/test/junit5/CoroutinesTimeoutNestedTest.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.debug.junit5
2 |
3 | import kotlinx.coroutines.*
4 | import org.junit.jupiter.api.*
5 |
6 | /**
7 | * This test checks that nested classes correctly recognize the [CoroutinesTimeout] annotation.
8 | *
9 | * This test class is not intended to be run manually. Instead, use [CoroutinesTimeoutTest] as the entry point.
10 | */
11 | @CoroutinesTimeout(200)
12 | class CoroutinesTimeoutNestedTest {
13 | @Nested
14 | inner class NestedInInherited {
15 | @Test
16 | fun usesOuterClassTimeout() = runBlocking {
17 | delay(1000)
18 | }
19 |
20 | @Test
21 | fun fitsInOuterClassTimeout() = runBlocking {
22 | delay(10)
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-debug/test/junit5/RegisterExtensionExample.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.debug.junit5
2 |
3 | import kotlinx.coroutines.*
4 | import org.junit.jupiter.api.*
5 | import org.junit.jupiter.api.extension.*
6 |
7 | class RegisterExtensionExample {
8 | @JvmField
9 | @RegisterExtension
10 | internal val timeout = CoroutinesTimeoutExtension.seconds(5)
11 |
12 | @Test
13 | fun testThatHangs() = runBlocking {
14 | delay(Long.MAX_VALUE) // somewhere deep in the stack
15 | }
16 | }
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/build.gradle.kts:
--------------------------------------------------------------------------------
1 | import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
2 |
3 | kotlin {
4 | sourceSets {
5 | jvmTest {
6 | dependencies {
7 | implementation(project(":kotlinx-coroutines-debug"))
8 | }
9 | }
10 | }
11 |
12 | @OptIn(ExperimentalWasmDsl::class)
13 | wasmJs {
14 | nodejs {
15 | testTask {
16 | filter.apply {
17 | // https://youtrack.jetbrains.com/issue/KT-61888
18 | excludeTest("TestDispatchersTest", "testMainMocking")
19 | }
20 | }
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/js/src/TestBuilders.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.test
2 |
3 | import kotlinx.coroutines.*
4 | import kotlinx.coroutines.test.internal.*
5 |
6 | public actual typealias TestResult = JsPromiseInterfaceForTesting
7 |
8 |
9 | @Suppress("CAST_NEVER_SUCCEEDS")
10 | internal actual fun createTestResult(testProcedure: suspend CoroutineScope.() -> Unit): TestResult =
11 | GlobalScope.promise {
12 | testProcedure()
13 | } as JsPromiseInterfaceForTesting
14 |
15 | internal actual fun dumpCoroutines() { }
16 |
17 | internal actual fun systemPropertyImpl(name: String): String? = null
18 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/js/src/internal/JsPromiseInterfaceForTesting.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.test.internal
2 |
3 | /* This is a declaration of JS's `Promise`. We need to keep it a separate class, because
4 | `actual typealias TestResult = Promise` fails: you can't instantiate an `expect class` with a typealias to
5 | a parametric class. So, we make a non-parametric class just for this. */
6 | /**
7 | * @suppress
8 | */
9 | @JsName("Promise")
10 | public external class JsPromiseInterfaceForTesting {
11 | /**
12 | * @suppress
13 | */
14 | public fun then(onFulfilled: ((Unit) -> Unit), onRejected: ((Throwable) -> Unit)): JsPromiseInterfaceForTesting
15 | /**
16 | * @suppress
17 | */
18 | public fun then(onFulfilled: ((Unit) -> Unit)): JsPromiseInterfaceForTesting
19 | }
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/js/src/internal/TestMainDispatcher.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.test.internal
2 | import kotlinx.coroutines.*
3 |
4 | @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") // do not remove the INVISIBLE_REFERENCE suppression: required in K2
5 | internal actual fun Dispatchers.getTestMainDispatcher(): TestMainDispatcher =
6 | when (val mainDispatcher = Main) {
7 | is TestMainDispatcher -> mainDispatcher
8 | else -> TestMainDispatcher(mainDispatcher).also { injectMain(it) }
9 | }
10 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/js/test/Helpers.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.test
2 |
3 | actual fun testResultChain(block: () -> TestResult, after: (Result) -> TestResult): TestResult =
4 | block().then(
5 | {
6 | after(Result.success(Unit))
7 | }, {
8 | after(Result.failure(it))
9 | })
10 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/js/test/PromiseTest.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.test
2 |
3 | import kotlinx.coroutines.*
4 | import kotlin.test.*
5 |
6 | class PromiseTest {
7 | @Test
8 | fun testCompletionFromPromise() = runTest {
9 | var promiseEntered = false
10 | val p = promise {
11 | delay(1)
12 | promiseEntered = true
13 | }
14 | delay(2)
15 | p.await()
16 | assertTrue(promiseEntered)
17 | }
18 | }
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/jvm/resources/META-INF/proguard/coroutines.pro:
--------------------------------------------------------------------------------
1 | # ServiceLoader support
2 | -keepnames class kotlinx.coroutines.test.internal.TestMainDispatcherFactory {}
3 | -keepnames class kotlinx.coroutines.android.AndroidExceptionPreHandler {}
4 | -keepnames class kotlinx.coroutines.android.AndroidDispatcherFactory {}
5 |
6 | # Most of volatile fields are updated with AFU and should not be mangled
7 | -keepclassmembers class kotlinx.coroutines.** {
8 | volatile ;
9 | }
10 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/jvm/resources/META-INF/services/kotlinx.coroutines.CoroutineExceptionHandler:
--------------------------------------------------------------------------------
1 | kotlinx.coroutines.test.internal.ExceptionCollectorAsService
2 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/jvm/resources/META-INF/services/kotlinx.coroutines.internal.MainDispatcherFactory:
--------------------------------------------------------------------------------
1 | kotlinx.coroutines.test.internal.TestMainDispatcherFactory
2 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/jvm/src/module-info.java:
--------------------------------------------------------------------------------
1 | import kotlinx.coroutines.CoroutineExceptionHandler;
2 | import kotlinx.coroutines.internal.MainDispatcherFactory;
3 | import kotlinx.coroutines.test.internal.ExceptionCollectorAsService;
4 | import kotlinx.coroutines.test.internal.TestMainDispatcherFactory;
5 |
6 | module kotlinx.coroutines.test {
7 | requires kotlin.stdlib;
8 | requires kotlinx.coroutines.core;
9 | requires kotlinx.atomicfu;
10 |
11 | exports kotlinx.coroutines.test;
12 |
13 | provides MainDispatcherFactory with TestMainDispatcherFactory;
14 | provides CoroutineExceptionHandler with ExceptionCollectorAsService;
15 | }
16 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/jvm/test/HelpersJvm.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.test
2 |
3 | actual fun testResultChain(block: () -> TestResult, after: (Result) -> TestResult): TestResult {
4 | try {
5 | block()
6 | after(Result.success(Unit))
7 | } catch (e: Throwable) {
8 | after(Result.failure(e))
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/jvm/test/MemoryLeakTest.kt:
--------------------------------------------------------------------------------
1 | import kotlinx.coroutines.*
2 | import kotlinx.coroutines.test.*
3 | import kotlinx.coroutines.testing.*
4 | import kotlin.test.*
5 |
6 | class MemoryLeakTest {
7 |
8 | @Test
9 | fun testCancellationLeakInTestCoroutineScheduler() = runTest {
10 | val leakingObject = Any()
11 | val job = launch(start = CoroutineStart.UNDISPATCHED) {
12 | delay(1)
13 | // This code is needed to hold a reference to `leakingObject` until the job itself is weakly reachable.
14 | leakingObject.hashCode()
15 | }
16 | job.cancel()
17 | FieldWalker.assertReachableCount(1, testScheduler) { it === leakingObject }
18 | runCurrent()
19 | FieldWalker.assertReachableCount(0, testScheduler) { it === leakingObject }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/jvm/test/RunTestStressTest.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.test
2 |
3 | import kotlinx.coroutines.*
4 | import kotlinx.coroutines.testing.*
5 | import kotlin.concurrent.*
6 | import kotlin.coroutines.*
7 | import kotlin.test.*
8 |
9 | class RunTestStressTest {
10 | /** Tests that notifications about asynchronous resumptions aren't lost. */
11 | @Test
12 | fun testRunTestActivityNotificationsRace() {
13 | val n = 1_000 * stressTestMultiplier
14 | for (i in 0 until n) {
15 | runTest {
16 | suspendCancellableCoroutine { cont ->
17 | thread {
18 | cont.resume(Unit)
19 | }
20 | }
21 | }
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/native/src/TestBuilders.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.test
2 | import kotlinx.coroutines.*
3 |
4 | public actual typealias TestResult = Unit
5 |
6 | internal actual fun createTestResult(testProcedure: suspend CoroutineScope.() -> Unit) {
7 | runBlocking {
8 | testProcedure()
9 | }
10 | }
11 |
12 | internal actual fun systemPropertyImpl(name: String): String? = null
13 |
14 | internal actual fun dumpCoroutines() { }
15 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/native/src/internal/TestMainDispatcher.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.test.internal
2 | import kotlinx.coroutines.*
3 |
4 | @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") // do not remove the INVISIBLE_REFERENCE suppression: required in K2
5 | internal actual fun Dispatchers.getTestMainDispatcher(): TestMainDispatcher =
6 | when (val mainDispatcher = Main) {
7 | is TestMainDispatcher -> mainDispatcher
8 | else -> TestMainDispatcher(mainDispatcher).also { injectMain(it) }
9 | }
10 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/native/test/Helpers.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.test
2 |
3 | actual fun testResultChain(block: () -> TestResult, after: (Result) -> TestResult): TestResult {
4 | try {
5 | block()
6 | after(Result.success(Unit))
7 | } catch (e: Throwable) {
8 | after(Result.failure(e))
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/npm/README.md:
--------------------------------------------------------------------------------
1 | # kotlinx-coroutines-test
2 |
3 | Testing support for `kotlinx-coroutines` in
4 | [Kotlin/JS](https://kotlinlang.org/docs/js-overview.html).
5 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/npm/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "kotlinx-coroutines-test",
3 | "version" : "$version",
4 | "description" : "Test utilities for kotlinx-coroutines",
5 | "main" : "kotlinx-coroutines-test.js",
6 | "author": "JetBrains",
7 | "license": "Apache-2.0",
8 | "homepage": "https://github.com/Kotlin/kotlinx.coroutines",
9 | "bugs": {
10 | "url": "https://github.com/Kotlin/kotlinx.coroutines/issues"
11 | },
12 | "repository": {
13 | "type": "git",
14 | "url": "git+https://github.com/Kotlin/kotlinx.coroutines.git"
15 | },
16 | "keywords": [
17 | "Kotlin",
18 | "async",
19 | "coroutines",
20 | "JetBrains",
21 | "test"
22 | ]
23 | }
24 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/wasmJs/src/TestBuilders.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.test
2 |
3 | import kotlinx.coroutines.*
4 | import kotlinx.coroutines.test.internal.*
5 | import kotlin.js.*
6 |
7 | public actual typealias TestResult = JsPromiseInterfaceForTesting
8 |
9 | @Suppress("INFERRED_TYPE_VARIABLE_INTO_POSSIBLE_EMPTY_INTERSECTION")
10 | internal actual fun createTestResult(testProcedure: suspend CoroutineScope.() -> Unit): TestResult =
11 | GlobalScope.promise {
12 | testProcedure()
13 | }.unsafeCast()
14 |
15 | internal actual fun dumpCoroutines() { }
16 |
17 | internal actual fun systemPropertyImpl(name: String): String? = null
18 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/wasmJs/src/internal/JsPromiseInterfaceForTesting.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.test.internal
2 |
3 | /* This is a declaration of JS's `Promise`. We need to keep it a separate class, because
4 | `actual typealias TestResult = Promise` fails: you can't instantiate an `expect class` with a typealias to
5 | a parametric class. So, we make a non-parametric class just for this. */
6 | /**
7 | * @suppress
8 | */
9 | @JsName("Promise")
10 | public external class JsPromiseInterfaceForTesting {
11 | /**
12 | * @suppress
13 | */
14 | public fun then(onFulfilled: ((JsAny) -> Unit), onRejected: ((JsAny) -> Unit)): JsPromiseInterfaceForTesting
15 | /**
16 | * @suppress
17 | */
18 | public fun then(onFulfilled: ((JsAny) -> Unit)): JsPromiseInterfaceForTesting
19 | }
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/wasmJs/src/internal/TestMainDispatcher.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.test.internal
2 | import kotlinx.coroutines.*
3 |
4 | @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
5 | internal actual fun Dispatchers.getTestMainDispatcher(): TestMainDispatcher =
6 | when (val mainDispatcher = Main) {
7 | is TestMainDispatcher -> mainDispatcher
8 | else -> TestMainDispatcher(mainDispatcher).also { injectMain(it) }
9 | }
10 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/wasmJs/test/Helpers.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.test
2 |
3 | actual fun testResultChain(block: () -> TestResult, after: (Result) -> TestResult): TestResult =
4 | block().then(
5 | {
6 | after(Result.success(Unit))
7 | null
8 | }, {
9 | after(Result.failure(it.toThrowableOrNull() ?: Throwable("Unexpected non-Kotlin exception $it")))
10 | null
11 | })
12 |
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/wasmJs/test/PromiseTest.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.test
2 |
3 | import kotlinx.coroutines.*
4 | import kotlin.test.*
5 |
6 | class PromiseTest {
7 | @Test
8 | fun testCompletionFromPromise() = runTest {
9 | var promiseEntered = false
10 | val p = promise {
11 | delay(1)
12 | promiseEntered = true
13 | }
14 | delay(2)
15 | p.await()
16 | assertTrue(promiseEntered)
17 | }
18 | }
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/wasmWasi/src/TestBuilders.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.test
2 |
3 | import kotlinx.coroutines.*
4 | import kotlinx.coroutines.internal.*
5 | import kotlin.coroutines.*
6 |
7 | @Suppress("ACTUAL_WITHOUT_EXPECT")
8 | public actual typealias TestResult = Unit
9 |
10 | internal actual fun systemPropertyImpl(name: String): String? = null
11 |
12 | internal actual fun createTestResult(testProcedure: suspend CoroutineScope.() -> Unit) =
13 | runTestCoroutine(EmptyCoroutineContext, testProcedure)
14 |
15 | internal actual fun dumpCoroutines() { }
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/wasmWasi/src/internal/TestMainDispatcher.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.test.internal
2 | import kotlinx.coroutines.*
3 |
4 | @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
5 | internal actual fun Dispatchers.getTestMainDispatcher(): TestMainDispatcher =
6 | when (val mainDispatcher = Main) {
7 | is TestMainDispatcher -> mainDispatcher
8 | else -> TestMainDispatcher(mainDispatcher).also { injectMain(it) }
9 | }
--------------------------------------------------------------------------------
/kotlinx-coroutines-test/wasmWasi/test/Helpers.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.test
2 |
3 | actual fun testResultChain(block: () -> TestResult, after: (Result) -> TestResult): TestResult {
4 | try {
5 | block()
6 | after(Result.success(Unit))
7 | } catch (e: Throwable) {
8 | after(Result.failure(e))
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/license/NOTICE.txt:
--------------------------------------------------------------------------------
1 | =========================================================================
2 | == NOTICE file corresponding to the section 4 d of ==
3 | == the Apache License, Version 2.0, ==
4 | == in this case for the kotlinx.coroutines library. ==
5 | =========================================================================
6 |
7 | kotlinx.coroutines library.
8 | Copyright 2016-2025 JetBrains s.r.o and contributors
9 |
--------------------------------------------------------------------------------
/reactive/README.md:
--------------------------------------------------------------------------------
1 | # Coroutines for reactive streams
2 |
3 | This directory contains modules with utilities for various reactive stream libraries.
4 | Module name below corresponds to the artifact name in Maven/Gradle.
5 |
6 | ## Modules
7 |
8 | * [kotlinx-coroutines-reactive](kotlinx-coroutines-reactive/README.md) -- utilities for [Reactive Streams](https://www.reactive-streams.org)
9 | * [kotlinx-coroutines-reactor](kotlinx-coroutines-reactor/README.md) -- utilities for [Reactor](https://projectreactor.io)
10 | * [kotlinx-coroutines-rx2](kotlinx-coroutines-rx2/README.md) -- utilities for [RxJava 2.x](https://github.com/ReactiveX/RxJava/tree/2.x)
11 | * [kotlinx-coroutines-rx3](kotlinx-coroutines-rx3/README.md) -- utilities for [RxJava 3.x](https://github.com/ReactiveX/RxJava)
12 |
--------------------------------------------------------------------------------
/reactive/knit.properties:
--------------------------------------------------------------------------------
1 | knit.package=kotlinx.coroutines.rx2.guide
2 | knit.dir=kotlinx-coroutines-rx2/test/guide/
3 |
--------------------------------------------------------------------------------
/reactive/knit.test.include:
--------------------------------------------------------------------------------
1 | // This file was automatically generated from ${file.name} by Knit tool. Do not edit.
2 | package ${test.package}
3 |
4 | import kotlinx.coroutines.testing.*
5 | import kotlinx.coroutines.guide.test.*
6 | import org.junit.Test
7 |
8 | class ${test.name} : ReactiveTestBase() {
--------------------------------------------------------------------------------
/reactive/kotlinx-coroutines-jdk9/README.md:
--------------------------------------------------------------------------------
1 | # Module kotlinx-coroutines-jdk9
2 |
3 | Utilities for [Java Flow](https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/Flow.html).
4 |
5 | Implemented as a collection of thin wrappers over [kotlinx-coroutines-reactive](../kotlinx-coroutines-reactive),
6 | an equivalent package for the Reactive Streams.
7 |
8 | # Package kotlinx.coroutines.jdk9
9 |
10 | Utilities for [Java Flow](https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/Flow.html).
11 |
--------------------------------------------------------------------------------
/reactive/kotlinx-coroutines-jdk9/build.gradle.kts:
--------------------------------------------------------------------------------
1 | import org.jetbrains.kotlin.gradle.dsl.*
2 |
3 | dependencies {
4 | implementation(project(":kotlinx-coroutines-reactive"))
5 | }
6 |
7 | java {
8 | sourceCompatibility = JavaVersion.VERSION_1_9
9 | targetCompatibility = JavaVersion.VERSION_1_9
10 | }
11 |
12 | tasks {
13 | compileKotlin {
14 | compilerOptions.jvmTarget = JvmTarget.JVM_9
15 | }
16 |
17 | compileTestKotlin {
18 | compilerOptions.jvmTarget = JvmTarget.JVM_9
19 | }
20 | }
21 |
22 | externalDocumentationLink(
23 | url = "https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/Flow.html"
24 | )
25 |
--------------------------------------------------------------------------------
/reactive/kotlinx-coroutines-jdk9/package.list:
--------------------------------------------------------------------------------
1 | java.util.concurrent.Flow
2 |
--------------------------------------------------------------------------------
/reactive/kotlinx-coroutines-jdk9/src/module-info.java:
--------------------------------------------------------------------------------
1 | @SuppressWarnings("JavaModuleNaming")
2 | module kotlinx.coroutines.jdk9 {
3 | requires kotlin.stdlib;
4 | requires kotlinx.coroutines.core;
5 | requires kotlinx.coroutines.reactive;
6 | requires org.reactivestreams;
7 |
8 | exports kotlinx.coroutines.jdk9;
9 | }
10 |
--------------------------------------------------------------------------------
/reactive/kotlinx-coroutines-jdk9/test/PublisherMultiTest.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.jdk9
2 |
3 | import kotlinx.coroutines.testing.*
4 | import kotlinx.coroutines.*
5 | import org.junit.Test
6 | import kotlin.test.*
7 |
8 | class PublisherMultiTest : TestBase() {
9 | @Test
10 | fun testConcurrentStress() = runBlocking {
11 | val n = 10_000 * stressTestMultiplier
12 | val observable = flowPublish {
13 | // concurrent emitters (many coroutines)
14 | val jobs = List(n) {
15 | // launch
16 | launch {
17 | send(it)
18 | }
19 | }
20 | jobs.forEach { it.join() }
21 | }
22 | val resultSet = mutableSetOf()
23 | observable.collect {
24 | assertTrue(resultSet.add(it))
25 | }
26 | assertEquals(n, resultSet.size)
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/reactive/kotlinx-coroutines-reactive/package.list:
--------------------------------------------------------------------------------
1 | org.reactivestreams
2 |
--------------------------------------------------------------------------------
/reactive/kotlinx-coroutines-reactive/src/ContextInjector.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.reactive
2 |
3 | import kotlinx.coroutines.InternalCoroutinesApi
4 | import org.reactivestreams.Publisher
5 | import kotlin.coroutines.CoroutineContext
6 |
7 | /** @suppress */
8 | @InternalCoroutinesApi
9 | public interface ContextInjector {
10 | /**
11 | * Injects `ReactorContext` element from the given context into the `SubscriberContext` of the publisher.
12 | * This API used as an indirection layer between `reactive` and `reactor` modules.
13 | */
14 | public fun injectCoroutineContext(publisher: Publisher, coroutineContext: CoroutineContext): Publisher
15 | }
16 |
--------------------------------------------------------------------------------
/reactive/kotlinx-coroutines-reactive/src/Convert.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.reactive
2 |
3 | import kotlinx.coroutines.channels.*
4 | import org.reactivestreams.*
5 | import kotlin.coroutines.*
6 |
7 | /** @suppress */
8 | @Deprecated(message = "Deprecated in the favour of consumeAsFlow()",
9 | level = DeprecationLevel.HIDDEN, // Error in 1.4, HIDDEN in 1.6.0
10 | replaceWith = ReplaceWith("this.consumeAsFlow().asPublisher(context)", imports = ["kotlinx.coroutines.flow.consumeAsFlow"]))
11 | public fun ReceiveChannel.asPublisher(context: CoroutineContext = EmptyCoroutineContext): Publisher = publish(context) {
12 | for (t in this@asPublisher)
13 | send(t)
14 | }
15 |
--------------------------------------------------------------------------------
/reactive/kotlinx-coroutines-reactive/src/module-info.java:
--------------------------------------------------------------------------------
1 | module kotlinx.coroutines.reactive {
2 | requires kotlin.stdlib;
3 | requires kotlinx.coroutines.core;
4 | requires kotlinx.atomicfu;
5 | requires org.reactivestreams;
6 |
7 | exports kotlinx.coroutines.reactive;
8 |
9 | uses kotlinx.coroutines.reactive.ContextInjector;
10 | }
11 |
--------------------------------------------------------------------------------
/reactive/kotlinx-coroutines-reactive/test/CancelledParentAttachTest.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.reactive
2 |
3 | import kotlinx.coroutines.testing.*
4 | import kotlinx.coroutines.*
5 | import kotlinx.coroutines.flow.*
6 | import org.junit.*
7 |
8 |
9 | class CancelledParentAttachTest : TestBase() {;
10 |
11 | @Test
12 | fun testFlow() = runTest {
13 | val f = flowOf(1, 2, 3).cancellable()
14 | val j = Job().also { it.cancel() }
15 | f.asPublisher(j).asFlow().collect()
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/reactive/kotlinx-coroutines-reactor/package.list:
--------------------------------------------------------------------------------
1 | reactor.adapter
2 | reactor.core
3 | reactor.core.publisher
4 | reactor.core.scheduler
5 | reactor.util
6 | reactor.util.annotation
7 | reactor.util.concurrent
8 | reactor.util.context
9 | reactor.util.function
10 |
--------------------------------------------------------------------------------
/reactive/kotlinx-coroutines-reactor/resources/META-INF/services/kotlinx.coroutines.reactive.ContextInjector:
--------------------------------------------------------------------------------
1 | kotlinx.coroutines.reactor.ReactorContextInjector
2 |
--------------------------------------------------------------------------------
/reactive/kotlinx-coroutines-reactor/src/Migration.kt:
--------------------------------------------------------------------------------
1 | @file:JvmName("FlowKt")
2 |
3 | package kotlinx.coroutines.reactor
4 |
5 | import kotlinx.coroutines.flow.*
6 | import reactor.core.publisher.*
7 |
8 | /** @suppress **/
9 | @Deprecated(
10 | message = "Replaced in favor of ReactiveFlow extension, please import kotlinx.coroutines.reactor.* instead of kotlinx.coroutines.reactor.FlowKt",
11 | level = DeprecationLevel.HIDDEN
12 | ) // Compatibility with Spring 5.2-RC
13 | @JvmName("asFlux")
14 | public fun Flow.asFluxDeprecated(): Flux = asFlux()
15 |
--------------------------------------------------------------------------------
/reactive/kotlinx-coroutines-reactor/src/module-info.java:
--------------------------------------------------------------------------------
1 | import kotlinx.coroutines.reactive.ContextInjector;
2 | import kotlinx.coroutines.reactor.ReactorContextInjector;
3 |
4 | module kotlinx.coroutines.reactor {
5 | requires kotlin.stdlib;
6 | requires kotlinx.coroutines.core;
7 | requires kotlinx.coroutines.reactive;
8 | requires org.reactivestreams;
9 | requires reactor.core;
10 |
11 | exports kotlinx.coroutines.reactor;
12 |
13 | provides ContextInjector with ReactorContextInjector;
14 | }
15 |
--------------------------------------------------------------------------------
/reactive/kotlinx-coroutines-rx2/package.list:
--------------------------------------------------------------------------------
1 | io.reactivex
2 | io.reactivex.annotations
3 | io.reactivex.disposables
4 | io.reactivex.exceptions
5 | io.reactivex.flowables
6 | io.reactivex.functions
7 | io.reactivex.observables
8 | io.reactivex.observers
9 | io.reactivex.parallel
10 | io.reactivex.plugins
11 | io.reactivex.processors
12 | io.reactivex.schedulers
13 | io.reactivex.subjects
14 | io.reactivex.subscribers
15 |
--------------------------------------------------------------------------------
/reactive/kotlinx-coroutines-rx2/src/RxCancellable.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.rx2
2 |
3 | import io.reactivex.functions.*
4 | import io.reactivex.plugins.*
5 | import kotlinx.coroutines.*
6 | import kotlin.coroutines.*
7 |
8 | internal class RxCancellable(private val job: Job) : Cancellable {
9 | override fun cancel() {
10 | job.cancel()
11 | }
12 | }
13 |
14 | internal fun handleUndeliverableException(cause: Throwable, context: CoroutineContext) {
15 | if (cause is CancellationException) return // Async CE should be completely ignored
16 | try {
17 | RxJavaPlugins.onError(cause)
18 | } catch (e: Throwable) {
19 | cause.addSuppressed(e)
20 | handleCoroutineException(context, cause)
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/reactive/kotlinx-coroutines-rx2/src/module-info.java:
--------------------------------------------------------------------------------
1 | @SuppressWarnings("JavaModuleNaming")
2 | module kotlinx.coroutines.rx2 {
3 | requires kotlin.stdlib;
4 | requires kotlinx.coroutines.core;
5 | requires kotlinx.coroutines.reactive;
6 | requires kotlinx.atomicfu;
7 | requires io.reactivex.rxjava2;
8 |
9 | exports kotlinx.coroutines.rx2;
10 | }
11 |
--------------------------------------------------------------------------------
/reactive/kotlinx-coroutines-rx3/package.list:
--------------------------------------------------------------------------------
1 | io.reactivex.rxjava3.core
2 | io.reactivex.rxjava3.annotations
3 | io.reactivex.rxjava3.disposables
4 | io.reactivex.rxjava3.exceptions
5 | io.reactivex.rxjava3.flowables
6 | io.reactivex.rxjava3.functions
7 | io.reactivex.rxjava3.observables
8 | io.reactivex.rxjava3.observers
9 | io.reactivex.rxjava3.parallel
10 | io.reactivex.rxjava3.plugins
11 | io.reactivex.rxjava3.processors
12 | io.reactivex.rxjava3.schedulers
13 | io.reactivex.rxjava3.subjects
14 | io.reactivex.rxjava3.subscribers
15 |
--------------------------------------------------------------------------------
/reactive/kotlinx-coroutines-rx3/src/RxCancellable.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.rx3
2 |
3 | import io.reactivex.rxjava3.functions.*
4 | import io.reactivex.rxjava3.plugins.*
5 | import kotlinx.coroutines.*
6 | import kotlin.coroutines.*
7 |
8 | internal class RxCancellable(private val job: Job) : Cancellable {
9 | override fun cancel() {
10 | job.cancel()
11 | }
12 | }
13 |
14 | internal fun handleUndeliverableException(cause: Throwable, context: CoroutineContext) {
15 | if (cause is CancellationException) return // Async CE should be completely ignored
16 | try {
17 | RxJavaPlugins.onError(cause)
18 | } catch (e: Throwable) {
19 | cause.addSuppressed(e)
20 | handleCoroutineException(context, cause)
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/reactive/kotlinx-coroutines-rx3/src/module-info.java:
--------------------------------------------------------------------------------
1 | @SuppressWarnings("JavaModuleNaming")
2 | module kotlinx.coroutines.rx3 {
3 | requires kotlin.stdlib;
4 | requires kotlinx.coroutines.core;
5 | requires kotlinx.coroutines.reactive;
6 | requires kotlinx.atomicfu;
7 | requires io.reactivex.rxjava3;
8 |
9 | exports kotlinx.coroutines.rx3;
10 | }
11 |
--------------------------------------------------------------------------------
/ui/README.md:
--------------------------------------------------------------------------------
1 | # Coroutines for UI
2 |
3 | This directory contains modules for coroutine programming with various single-threaded UI libraries.
4 | After adding dependency to the UI library, corresponding UI dispatcher will be available via `Dispatchers.Main`.
5 | Module name below corresponds to the artifact name in Maven/Gradle.
6 |
7 | ## Modules
8 |
9 | * [kotlinx-coroutines-android](kotlinx-coroutines-android/README.md) -- `Dispatchers.Main` context for Android applications.
10 | * [kotlinx-coroutines-javafx](kotlinx-coroutines-javafx/README.md) -- `Dispatchers.JavaFx` context for JavaFX UI applications.
11 | * [kotlinx-coroutines-swing](kotlinx-coroutines-swing/README.md) -- `Dispatchers.Swing` context for Swing UI applications.
12 |
--------------------------------------------------------------------------------
/ui/knit.properties:
--------------------------------------------------------------------------------
1 | knit.dir=kotlinx-coroutines-javafx/test/guide/
2 | knit.package=kotlinx.coroutines.javafx.guide
3 | knit.include=knit.code.include
4 |
--------------------------------------------------------------------------------
/ui/kotlinx-coroutines-android/android-unit-tests/build.gradle.kts:
--------------------------------------------------------------------------------
1 | project.configureAar()
2 |
3 | dependencies {
4 | configureAarUnpacking()
5 |
6 | testImplementation("com.google.android:android:${version("android")}")
7 | testImplementation("org.robolectric:robolectric:${version("robolectric")}")
8 | // Required by robolectric
9 | testImplementation("androidx.test:core:1.2.0")
10 | testImplementation("androidx.test:monitor:1.2.0")
11 |
12 | testImplementation(project(":kotlinx-coroutines-test"))
13 | testImplementation(project(":kotlinx-coroutines-android"))
14 | }
15 |
--------------------------------------------------------------------------------
/ui/kotlinx-coroutines-android/android-unit-tests/resources/META-INF/services/kotlinx.coroutines.CoroutineScope:
--------------------------------------------------------------------------------
1 | kotlinx.coroutines.android.EmptyCoroutineScopeImpl1
2 | kotlinx.coroutines.android.EmptyCoroutineScopeImpl2
3 | # testing configuration file parsing # kotlinx.coroutines.service.loader.LocalEmptyCoroutineScope2
4 |
5 | kotlinx.coroutines.android.EmptyCoroutineScopeImpl2
6 |
7 | kotlinx.coroutines.android.EmptyCoroutineScopeImpl1
8 |
9 |
10 | kotlinx.coroutines.android.EmptyCoroutineScopeImpl1
11 |
12 |
13 | kotlinx.coroutines.android.EmptyCoroutineScopeImpl3#comment
--------------------------------------------------------------------------------
/ui/kotlinx-coroutines-android/android-unit-tests/src/EmptyCoroutineScopeImpl.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.android
2 |
3 | import kotlinx.coroutines.*
4 | import kotlin.coroutines.*
5 |
6 | // Classes for testing service loader
7 | internal class EmptyCoroutineScopeImpl1 : CoroutineScope {
8 | override val coroutineContext: CoroutineContext
9 | get() = EmptyCoroutineContext
10 | }
11 |
12 | internal class EmptyCoroutineScopeImpl2 : CoroutineScope {
13 | override val coroutineContext: CoroutineContext
14 | get() = EmptyCoroutineContext
15 | }
16 |
17 | internal class EmptyCoroutineScopeImpl3 : CoroutineScope {
18 | override val coroutineContext: CoroutineContext
19 | get() = EmptyCoroutineContext
20 | }
21 |
--------------------------------------------------------------------------------
/ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests/MockedMainTest.kt:
--------------------------------------------------------------------------------
1 | package ordered.tests
2 |
3 | class MockedMainTest : FirstMockedMainTest()
4 |
--------------------------------------------------------------------------------
/ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests/RobolectricTest.kt:
--------------------------------------------------------------------------------
1 | package ordered.tests
2 |
3 | open class RobolectricTest : FirstRobolectricTest()
4 |
--------------------------------------------------------------------------------
/ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests/TestComponent.kt:
--------------------------------------------------------------------------------
1 | package ordered.tests
2 |
3 | import kotlinx.coroutines.*
4 |
5 | public class TestComponent {
6 | internal lateinit var caughtException: Throwable
7 | private val scope =
8 | CoroutineScope(SupervisorJob() + Dispatchers.Main + CoroutineExceptionHandler { _, e -> caughtException = e})
9 | public var launchCompleted = false
10 | public var delayedLaunchCompleted = false
11 |
12 | fun launchSomething() {
13 | scope.launch {
14 | launchCompleted = true
15 | }
16 | }
17 |
18 | fun launchDelayed() {
19 | scope.launch {
20 | delay(Long.MAX_VALUE / 2)
21 | delayedLaunchCompleted = true
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/ui/kotlinx-coroutines-android/resources/META-INF/com.android.tools/proguard/coroutines.pro:
--------------------------------------------------------------------------------
1 | # When editing this file, update the following files as well:
2 | # - META-INF/com.android.tools/r8-upto-3.0.0/coroutines.pro
3 | # - META-INF/proguard/coroutines.pro
4 |
5 | -keep class kotlinx.coroutines.android.AndroidDispatcherFactory {*;}
6 | -keep class kotlinx.coroutines.android.AndroidExceptionPreHandler {*;}
7 |
--------------------------------------------------------------------------------
/ui/kotlinx-coroutines-android/resources/META-INF/com.android.tools/r8-upto-3.0.0/coroutines.pro:
--------------------------------------------------------------------------------
1 | # When editing this file, update the following files as well for AGP 3.6.0+:
2 | # - META-INF/com.android.tools/proguard/coroutines.pro
3 | # - META-INF/proguard/coroutines.pro
4 |
5 | # After R8 3.0.0 (or probably sometime before that), R8 learned how to optimize
6 | # classes mentioned in META-INF/services files, and explicitly -keeping them
7 | # disables these optimizations.
8 | # https://github.com/Kotlin/kotlinx.coroutines/issues/3111
9 | -keep class kotlinx.coroutines.android.AndroidDispatcherFactory {*;}
10 | -keep class kotlinx.coroutines.android.AndroidExceptionPreHandler {*;}
11 |
--------------------------------------------------------------------------------
/ui/kotlinx-coroutines-android/resources/META-INF/proguard/coroutines.pro:
--------------------------------------------------------------------------------
1 | # Files in this directory will be ignored starting with Android Gradle Plugin 3.6.0+
2 |
3 | # When editing this file, update the following files as well for AGP 3.6.0+:
4 | # - META-INF/com.android.tools/proguard/coroutines.pro
5 | # - META-INF/com.android.tools/r8-upto-3.0.0/coroutines.pro
6 |
7 | -keep class kotlinx.coroutines.android.AndroidDispatcherFactory {*;}
8 | -keep class kotlinx.coroutines.android.AndroidExceptionPreHandler {*;}
9 |
--------------------------------------------------------------------------------
/ui/kotlinx-coroutines-android/resources/META-INF/services/kotlinx.coroutines.CoroutineExceptionHandler:
--------------------------------------------------------------------------------
1 | kotlinx.coroutines.android.AndroidExceptionPreHandler
2 |
--------------------------------------------------------------------------------
/ui/kotlinx-coroutines-android/resources/META-INF/services/kotlinx.coroutines.internal.MainDispatcherFactory:
--------------------------------------------------------------------------------
1 | kotlinx.coroutines.android.AndroidDispatcherFactory
2 |
--------------------------------------------------------------------------------
/ui/kotlinx-coroutines-android/src/module-info.java:
--------------------------------------------------------------------------------
1 | import kotlinx.coroutines.android.AndroidDispatcherFactory;
2 | import kotlinx.coroutines.internal.MainDispatcherFactory;
3 |
4 | module kotlinx.coroutines.android {
5 | requires kotlin.stdlib;
6 | requires kotlinx.coroutines.core;
7 |
8 | exports kotlinx.coroutines.android;
9 |
10 | provides MainDispatcherFactory with AndroidDispatcherFactory;
11 | }
12 |
--------------------------------------------------------------------------------
/ui/kotlinx-coroutines-android/testdata/r8-test-common.pro:
--------------------------------------------------------------------------------
1 | # Entry point for retaining MainDispatcherLoader which uses a ServiceLoader.
2 | -keep class kotlinx.coroutines.Dispatchers {
3 | ** getMain();
4 | }
5 |
6 | # Entry point for retaining CoroutineExceptionHandlerImpl.handlers which uses a ServiceLoader.
7 | -keep class kotlinx.coroutines.CoroutineExceptionHandlerKt {
8 | void handleCoroutineException(...);
9 | }
10 |
11 | # Entry point for the rest of coroutines machinery
12 | -keep class kotlinx.coroutines.BuildersKt {
13 | ** runBlocking(...);
14 | ** launch(...);
15 | }
16 |
17 | # We are cheating a bit by not having android.jar on R8's library classpath. Ignore those warnings.
18 | -ignorewarnings
--------------------------------------------------------------------------------
/ui/kotlinx-coroutines-android/testdata/r8-test-rules-no-optim.pro:
--------------------------------------------------------------------------------
1 | -include r8-test-common.pro
2 |
3 | # Include the shrinker config used by legacy versions of AGP and ProGuard
4 | -include ../resources/META-INF/com.android.tools/proguard/coroutines.pro
5 |
--------------------------------------------------------------------------------
/ui/kotlinx-coroutines-android/testdata/r8-test-rules.pro:
--------------------------------------------------------------------------------
1 | -include r8-test-common.pro
2 |
3 | -include ../resources/META-INF/com.android.tools/r8-from-1.6.0/coroutines.pro
4 |
5 | # Validate that service-loader & debugger classes are discarded
6 | -checkdiscard class kotlinx.coroutines.internal.FastServiceLoader
7 | -checkdiscard class kotlinx.coroutines.DebugKt
8 | -checkdiscard class kotlinx.coroutines.internal.StackTraceRecoveryKt
9 | -checkdiscard class kotlinx.coroutines.debug.DebugProbesKt
10 |
11 | # Real android projects do not keep this class, but somehow it is kept in this test (R8 bug)
12 | # -checkdiscard class kotlinx.coroutines.internal.MissingMainCoroutineDispatcher
13 |
14 | # Should not keep this class, but it is still there (R8 bug)
15 | #-checkdiscard class kotlinx.coroutines.CoroutineId
16 |
--------------------------------------------------------------------------------
/ui/kotlinx-coroutines-javafx/README.md:
--------------------------------------------------------------------------------
1 | # Module kotlinx-coroutines-javafx
2 |
3 | Provides `Dispatchers.JavaFx` context and `Dispatchers.Main` implementation for JavaFX UI applications.
4 |
5 | Read [Guide to UI programming with coroutines](https://github.com/Kotlin/kotlinx.coroutines/blob/master/ui/coroutines-guide-ui.md)
6 | for tutorial on this module.
7 |
8 | # Package kotlinx.coroutines.javafx
9 |
10 | Provides `Dispatchers.JavaFx` context and `Dispatchers.Main` implementation for JavaFX UI applications.
11 |
--------------------------------------------------------------------------------
/ui/kotlinx-coroutines-javafx/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.openjfx.javafxplugin") version "0.0.14"
3 | }
4 |
5 | configurations {
6 | register("javafx")
7 | named("compileOnly") {
8 | extendsFrom(configurations["javafx"])
9 | }
10 | named("testImplementation") {
11 | extendsFrom(configurations["javafx"])
12 | }
13 | }
14 |
15 | javafx {
16 | version = version("javafx")
17 | modules = listOf("javafx.controls")
18 | configuration = "javafx"
19 | }
20 |
21 | // Fixup moduleplugin in order to properly run with classpath
22 | tasks {
23 | test {
24 | extensions.configure(org.javamodularity.moduleplugin.extensions.TestModuleOptions::class) {
25 | addReads["kotlinx.coroutines.javafx"] = "kotlin.test,test.utils.jvm"
26 | addReads["test.utils.jvm"] = "junit,kotlin.test"
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/ui/kotlinx-coroutines-javafx/resources/META-INF/services/kotlinx.coroutines.internal.MainDispatcherFactory:
--------------------------------------------------------------------------------
1 | kotlinx.coroutines.javafx.JavaFxDispatcherFactory
2 |
--------------------------------------------------------------------------------
/ui/kotlinx-coroutines-javafx/src/module-info.java:
--------------------------------------------------------------------------------
1 | import kotlinx.coroutines.internal.MainDispatcherFactory;
2 | import kotlinx.coroutines.javafx.JavaFxDispatcherFactory;
3 |
4 | module kotlinx.coroutines.javafx {
5 | requires kotlin.stdlib;
6 | requires kotlinx.coroutines.core;
7 | requires javafx.base;
8 | requires javafx.graphics;
9 |
10 | exports kotlinx.coroutines.javafx;
11 |
12 | provides MainDispatcherFactory with JavaFxDispatcherFactory;
13 | }
14 |
--------------------------------------------------------------------------------
/ui/kotlinx-coroutines-swing/README.md:
--------------------------------------------------------------------------------
1 | # Module kotlinx-coroutines-swing
2 |
3 | Provides `Dispatchers.Swing` context and `Dispatchers.Main` implementation for Swing UI applications.
4 |
5 | Read [Guide to UI programming with coroutines](https://github.com/Kotlin/kotlinx.coroutines/blob/master/ui/coroutines-guide-ui.md)
6 | for tutorial on this module.
7 |
8 | # Package kotlinx.coroutines.swing
9 |
10 | Provides `Dispatchers.Swing` context and `Dispatchers.Main` implementation for Swing UI applications.
11 |
--------------------------------------------------------------------------------
/ui/kotlinx-coroutines-swing/api/kotlinx-coroutines-swing.api:
--------------------------------------------------------------------------------
1 | public abstract class kotlinx/coroutines/swing/SwingDispatcher : kotlinx/coroutines/MainCoroutineDispatcher, kotlinx/coroutines/Delay {
2 | public fun delay (JLkotlin/coroutines/Continuation;)Ljava/lang/Object;
3 | public fun dispatch (Lkotlin/coroutines/CoroutineContext;Ljava/lang/Runnable;)V
4 | public fun invokeOnTimeout (JLjava/lang/Runnable;Lkotlin/coroutines/CoroutineContext;)Lkotlinx/coroutines/DisposableHandle;
5 | public fun scheduleResumeAfterDelay (JLkotlinx/coroutines/CancellableContinuation;)V
6 | }
7 |
8 | public final class kotlinx/coroutines/swing/SwingDispatcherKt {
9 | public static final fun getSwing (Lkotlinx/coroutines/Dispatchers;)Lkotlinx/coroutines/swing/SwingDispatcher;
10 | }
11 |
12 |
--------------------------------------------------------------------------------
/ui/kotlinx-coroutines-swing/build.gradle.kts:
--------------------------------------------------------------------------------
1 | dependencies {
2 | testImplementation(project(":kotlinx-coroutines-jdk8"))
3 | }
4 |
--------------------------------------------------------------------------------
/ui/kotlinx-coroutines-swing/resources/META-INF/services/kotlinx.coroutines.internal.MainDispatcherFactory:
--------------------------------------------------------------------------------
1 | kotlinx.coroutines.swing.SwingDispatcherFactory
2 |
--------------------------------------------------------------------------------
/ui/kotlinx-coroutines-swing/src/module-info.java:
--------------------------------------------------------------------------------
1 | import kotlinx.coroutines.internal.MainDispatcherFactory;
2 | import kotlinx.coroutines.swing.SwingDispatcherFactory;
3 |
4 | module kotlinx.coroutines.swing {
5 | requires kotlin.stdlib;
6 | requires kotlinx.coroutines.core;
7 | requires java.desktop;
8 |
9 | exports kotlinx.coroutines.swing;
10 |
11 | provides MainDispatcherFactory with SwingDispatcherFactory;
12 | }
13 |
--------------------------------------------------------------------------------
/ui/kotlinx-coroutines-swing/test/SwingTest.kt:
--------------------------------------------------------------------------------
1 | package kotlinx.coroutines.swing
2 |
3 | import kotlinx.coroutines.testing.*
4 | import kotlinx.coroutines.*
5 | import org.junit.*
6 | import org.junit.Test
7 | import javax.swing.*
8 | import kotlin.test.*
9 |
10 | class SwingTest : MainDispatcherTestBase.WithRealTimeDelay() {
11 | @Before
12 | fun setup() {
13 | ignoreLostThreads("AWT-EventQueue-")
14 | }
15 |
16 | override fun isMainThread() = SwingUtilities.isEventDispatchThread()
17 |
18 | override fun scheduleOnMainQueue(block: () -> Unit) {
19 | SwingUtilities.invokeLater { block() }
20 | }
21 |
22 | /** Tests that the Main dispatcher is in fact the JavaFx one. */
23 | @Test
24 | fun testMainIsJavaFx() {
25 | assertSame(Dispatchers.Swing, Dispatchers.Main)
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/ui/ui-example-android.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/ui/ui-example-android.png
--------------------------------------------------------------------------------
/ui/ui-example-javafx.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kotlin/kotlinx.coroutines/f4f519b36734238ec686dfaec1e174086691781e/ui/ui-example-javafx.png
--------------------------------------------------------------------------------