From 8c11a31c575b356e7d2e0e9f52d95d5496079184 Mon Sep 17 00:00:00 2001 From: Roman Elizarov Date: Tue, 16 Jun 2020 11:23:48 +0300 Subject: [PATCH] ~ Fixup kotlinx-coroutines-rx3 module to internal API changes --- kotlinx-coroutines-core/jvm/test/Scratch.kt | 54 +++++++++++++++++++ .../kotlinx-coroutines-rx3/src/RxChannel.kt | 2 +- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 kotlinx-coroutines-core/jvm/test/Scratch.kt diff --git a/kotlinx-coroutines-core/jvm/test/Scratch.kt b/kotlinx-coroutines-core/jvm/test/Scratch.kt new file mode 100644 index 0000000000..03cf10ecc0 --- /dev/null +++ b/kotlinx-coroutines-core/jvm/test/Scratch.kt @@ -0,0 +1,54 @@ +/* + * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +package kotlinx.coroutines + +import org.junit.* +import kotlin.coroutines.* + +class Scratch : TestBase() { + + @Test + fun test1() = runTest(expected = { it is CancellationException }) { + suspendCancellableCoroutine { c -> + c.invokeOnCancellation { + println(it) + } + c.cancel() + } + } + + @Test + fun test2() = runTest(expected = { it is CancellationException }) { + suspendCancellableCoroutine { c -> + c.cancel() + c.invokeOnCancellation { + println(it) + } + } + } + + @Test + fun test3() = runTest { + suspendCancellableCoroutine { c -> + c.invokeOnCancellation { + println("Invoked") // Printed + } + assertFailsWith { + c.invokeOnCancellation { expectUnreached() } // Triggers ISE + } + c.resume(Unit) + } + } + + @Test + fun test4() = runTest(expected = { it is IllegalStateException }) { + suspendCancellableCoroutine { c -> + c.invokeOnCancellation { + println("Invoked") // Not printed + } + c.resumeWith(Result.failure(IllegalStateException())) + } + } +} \ No newline at end of file diff --git a/reactive/kotlinx-coroutines-rx3/src/RxChannel.kt b/reactive/kotlinx-coroutines-rx3/src/RxChannel.kt index acb907b765..737cf6710d 100644 --- a/reactive/kotlinx-coroutines-rx3/src/RxChannel.kt +++ b/reactive/kotlinx-coroutines-rx3/src/RxChannel.kt @@ -54,7 +54,7 @@ public suspend inline fun ObservableSource.collect(action: (T) -> Unit): @Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") private class SubscriptionChannel : - LinkedListChannel(), Observer, MaybeObserver + LinkedListChannel(null), Observer, MaybeObserver { private val _subscription = atomic(null)