-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate awaitSingleOr*, specialize some await* functions for Mono a…
…nd Maybe (#2628) * Deprecated `awaitSingleOr*` on arbitrary Publishers * Added specialized `awaitSingle` and `awaitSingleOrNull` methods on `Maybe<T>` and `Mono<T>` * Deprecated `Maybe<T>.await()` in favor of `Maybe<T>.awaitSingleOrNull()` * Added specializations of most of the `await*` methods for `Mono<T>` and deprecated them, as the only useful methods on `Mono<T>` are `awaitSingle` and `awaitSingleOrNull` * Reworded some documentation for `await*` methods Fixes #2591 Fixes #1587
- Loading branch information
1 parent
cefb84f
commit 71df60e
Showing
22 changed files
with
871 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.coroutines.jdk9 | ||
|
||
import kotlinx.coroutines.* | ||
import org.junit.* | ||
import java.util.concurrent.Flow as JFlow | ||
|
||
class AwaitTest: TestBase() { | ||
|
||
/** Tests that calls to [awaitFirst] (and, thus, to the rest of these functions) throw [CancellationException] and | ||
* unsubscribe from the publisher when their [Job] is cancelled. */ | ||
@Test | ||
fun testAwaitCancellation() = runTest { | ||
expect(1) | ||
val publisher = JFlow.Publisher<Int> { s -> | ||
s.onSubscribe(object : JFlow.Subscription { | ||
override fun request(n: Long) { | ||
expect(3) | ||
} | ||
|
||
override fun cancel() { | ||
expect(5) | ||
} | ||
}) | ||
} | ||
val job = launch(start = CoroutineStart.UNDISPATCHED) { | ||
try { | ||
expect(2) | ||
publisher.awaitFirst() | ||
} catch (e: CancellationException) { | ||
expect(6) | ||
throw e | ||
} | ||
} | ||
expect(4) | ||
job.cancelAndJoin() | ||
finish(7) | ||
} | ||
|
||
} |
Oops, something went wrong.