diff --git a/kotlinx-coroutines-core/common/src/Await.kt b/kotlinx-coroutines-core/common/src/Await.kt index fd78899834..ec80b9fcbc 100644 --- a/kotlinx-coroutines-core/common/src/Await.kt +++ b/kotlinx-coroutines-core/common/src/Await.kt @@ -11,11 +11,10 @@ import kotlin.coroutines.* * This function is **not** equivalent to `deferreds.map { it.await() }` which fails only when it sequentially * gets to wait for the failing deferred, while this `awaitAll` fails immediately as soon as any of the deferreds fail. * - * This suspending function is cancellable. - * If the [Job] of the current coroutine is cancelled or completed while this suspending function is waiting, - * this function immediately resumes with [CancellationException]. - * There is a **prompt cancellation guarantee**. If the job was cancelled while this function was - * suspended, it will not resume successfully. See [suspendCancellableCoroutine] documentation for low-level details. + * This suspending function is cancellable: if the [Job] of the current coroutine is cancelled or completed while this + * suspending function is waiting, this function immediately resumes with [CancellationException]. + * There is a **prompt cancellation guarantee**: even if this function is ready to return the result, but was cancelled + * while suspended, [CancellationException] will be thrown. See [suspendCancellableCoroutine] for low-level details. */ public suspend fun awaitAll(vararg deferreds: Deferred): List = if (deferreds.isEmpty()) emptyList() else AwaitAll(deferreds).await() @@ -28,11 +27,10 @@ public suspend fun awaitAll(vararg deferreds: Deferred): List = * This function is **not** equivalent to `this.map { it.await() }` which fails only when it sequentially * gets to wait for the failing deferred, while this `awaitAll` fails immediately as soon as any of the deferreds fail. * - * This suspending function is cancellable. - * If the [Job] of the current coroutine is cancelled or completed while this suspending function is waiting, - * this function immediately resumes with [CancellationException]. - * There is a **prompt cancellation guarantee**. If the job was cancelled while this function was - * suspended, it will not resume successfully. See [suspendCancellableCoroutine] documentation for low-level details. + * This suspending function is cancellable: if the [Job] of the current coroutine is cancelled or completed while this + * suspending function is waiting, this function immediately resumes with [CancellationException]. + * There is a **prompt cancellation guarantee**: even if this function is ready to return the result, but was cancelled + * while suspended, [CancellationException] will be thrown. See [suspendCancellableCoroutine] for low-level details. */ public suspend fun Collection>.awaitAll(): List = if (isEmpty()) emptyList() else AwaitAll(toTypedArray()).await() @@ -41,11 +39,10 @@ public suspend fun Collection>.awaitAll(): List = * Suspends current coroutine until all given jobs are complete. * This method is semantically equivalent to joining all given jobs one by one with `jobs.forEach { it.join() }`. * - * This suspending function is cancellable. - * If the [Job] of the current coroutine is cancelled or completed while this suspending function is waiting, - * this function immediately resumes with [CancellationException]. - * There is a **prompt cancellation guarantee**. If the job was cancelled while this function was - * suspended, it will not resume successfully. See [suspendCancellableCoroutine] documentation for low-level details. + * This suspending function is cancellable: if the [Job] of the current coroutine is cancelled or completed while this + * suspending function is waiting, this function immediately resumes with [CancellationException]. + * There is a **prompt cancellation guarantee**: even if this function is ready to return the result, but was cancelled + * while suspended, [CancellationException] will be thrown. See [suspendCancellableCoroutine] for low-level details. */ public suspend fun joinAll(vararg jobs: Job): Unit = jobs.forEach { it.join() } @@ -53,11 +50,10 @@ public suspend fun joinAll(vararg jobs: Job): Unit = jobs.forEach { it.join() } * Suspends current coroutine until all given jobs are complete. * This method is semantically equivalent to joining all given jobs one by one with `forEach { it.join() }`. * - * This suspending function is cancellable. - * If the [Job] of the current coroutine is cancelled or completed while this suspending function is waiting, - * this function immediately resumes with [CancellationException]. - * There is a **prompt cancellation guarantee**. If the job was cancelled while this function was - * suspended, it will not resume successfully. See [suspendCancellableCoroutine] documentation for low-level details. + * This suspending function is cancellable: if the [Job] of the current coroutine is cancelled or completed while this + * suspending function is waiting, this function immediately resumes with [CancellationException]. + * There is a **prompt cancellation guarantee**: even if this function is ready to return the result, but was cancelled + * while suspended, [CancellationException] will be thrown. See [suspendCancellableCoroutine] for low-level details. */ public suspend fun Collection.joinAll(): Unit = forEach { it.join() } diff --git a/kotlinx-coroutines-core/common/src/CancellableContinuation.kt b/kotlinx-coroutines-core/common/src/CancellableContinuation.kt index 4b31966ee9..e4bca096ab 100644 --- a/kotlinx-coroutines-core/common/src/CancellableContinuation.kt +++ b/kotlinx-coroutines-core/common/src/CancellableContinuation.kt @@ -238,25 +238,25 @@ public interface CancellableContinuation : Continuation { * * This function provides **prompt cancellation guarantee**. * If the [Job] of the current coroutine was cancelled while this function was suspended it will not resume - * successfully. + * successfully, even if [CancellableContinuation.resume] was already invoked. * * The cancellation of the coroutine's job is generally asynchronous with respect to the suspended coroutine. - * The suspended coroutine is resumed with the call it to its [Continuation.resumeWith] member function or to + * The suspended coroutine is resumed with a call to its [Continuation.resumeWith] member function or to the * [resume][Continuation.resume] extension function. * However, when coroutine is resumed, it does not immediately start executing, but is passed to its * [CoroutineDispatcher] to schedule its execution when dispatcher's resources become available for execution. - * The job's cancellation can happen both before, after, and concurrently with the call to `resume`. In any - * case, prompt cancellation guarantees that the the coroutine will not resume its code successfully. + * The job's cancellation can happen before, after, and concurrently with the call to `resume`. In any + * case, prompt cancellation guarantees that the coroutine will not resume its code successfully. * * If the coroutine was resumed with an exception (for example, using [Continuation.resumeWithException] extension - * function) and cancelled, then the resulting exception of the `suspendCancellableCoroutine` function is determined - * by whichever action (exceptional resume or cancellation) that happened first. + * function) and cancelled, then the exception thrown by the `suspendCancellableCoroutine` function is determined + * by what happened first: exceptional resume or cancellation. * * ### Returning resources from a suspended coroutine * - * As a result of a prompt cancellation guarantee, when a closeable resource - * (like open file or a handle to another native resource) is returned from a suspended coroutine as a value - * it can be lost when the coroutine is cancelled. In order to ensure that the resource can be properly closed + * As a result of the prompt cancellation guarantee, when a closeable resource + * (like open file or a handle to another native resource) is returned from a suspended coroutine as a value, + * it can be lost when the coroutine is cancelled. To ensure that the resource can be properly closed * in this case, the [CancellableContinuation] interface provides two functions. * * - [invokeOnCancellation][CancellableContinuation.invokeOnCancellation] installs a handler that is called diff --git a/kotlinx-coroutines-core/common/src/Deferred.kt b/kotlinx-coroutines-core/common/src/Deferred.kt index fd53919b40..afec2cc4ef 100644 --- a/kotlinx-coroutines-core/common/src/Deferred.kt +++ b/kotlinx-coroutines-core/common/src/Deferred.kt @@ -58,8 +58,8 @@ public interface Deferred : Job { * } * ``` * - * There is a **prompt cancellation guarantee**. If the job was cancelled while this function was - * suspended, it will not resume successfully. See [suspendCancellableCoroutine] documentation for low-level details. + * There is a **prompt cancellation guarantee**: even if this function is ready to return the result, but was cancelled + * while suspended, [CancellationException] will be thrown. See [suspendCancellableCoroutine] for low-level details. * * This function can be used in [select] invocations with an [onAwait] clause. * Use [isCompleted] to check for completion of this deferred value without waiting, and diff --git a/kotlinx-coroutines-core/common/src/Delay.kt b/kotlinx-coroutines-core/common/src/Delay.kt index 48f78b4ea0..a4dccf360c 100644 --- a/kotlinx-coroutines-core/common/src/Delay.kt +++ b/kotlinx-coroutines-core/common/src/Delay.kt @@ -106,11 +106,10 @@ public suspend fun awaitCancellation(): Nothing = suspendCancellableCoroutine {} * Delays coroutine for at least the given time without blocking a thread and resumes it after a specified time. * If the given [timeMillis] is non-positive, this function returns immediately. * - * This suspending function is cancellable. - * If the [Job] of the current coroutine is cancelled or completed while this suspending function is waiting, this function - * immediately resumes with [CancellationException]. - * There is a **prompt cancellation guarantee**. If the job was cancelled while this function was - * suspended, it will not resume successfully. See [suspendCancellableCoroutine] documentation for low-level details. + * This suspending function is cancellable: if the [Job] of the current coroutine is cancelled or completed while this + * suspending function is waiting, this function immediately resumes with [CancellationException]. + * There is a **prompt cancellation guarantee**: even if this function is ready to return the result, but was cancelled + * while suspended, [CancellationException] will be thrown. See [suspendCancellableCoroutine] for low-level details. * * If you want to delay forever (until cancellation), consider using [awaitCancellation] instead. * @@ -133,11 +132,10 @@ public suspend fun delay(timeMillis: Long) { * Delays coroutine for at least the given [duration] without blocking a thread and resumes it after the specified time. * If the given [duration] is non-positive, this function returns immediately. * - * This suspending function is cancellable. - * If the [Job] of the current coroutine is cancelled or completed while this suspending function is waiting, this function - * immediately resumes with [CancellationException]. - * There is a **prompt cancellation guarantee**. If the job was cancelled while this function was - * suspended, it will not resume successfully. See [suspendCancellableCoroutine] documentation for low-level details. + * This suspending function is cancellable: if the [Job] of the current coroutine is cancelled or completed while this + * suspending function is waiting, this function immediately resumes with [CancellationException]. + * There is a **prompt cancellation guarantee**: even if this function is ready to return the result, but was cancelled + * while suspended, [CancellationException] will be thrown. See [suspendCancellableCoroutine] for low-level details. * * If you want to delay forever (until cancellation), consider using [awaitCancellation] instead. * diff --git a/kotlinx-coroutines-core/common/src/Yield.kt b/kotlinx-coroutines-core/common/src/Yield.kt index c6a157f10e..b02d90d87a 100644 --- a/kotlinx-coroutines-core/common/src/Yield.kt +++ b/kotlinx-coroutines-core/common/src/Yield.kt @@ -6,12 +6,11 @@ import kotlin.coroutines.intrinsics.* /** * Yields the thread (or thread pool) of the current coroutine dispatcher * to other coroutines on the same dispatcher to run if possible. - * - * This suspending function is cancellable. - * If the [Job] of the current coroutine is cancelled or completed when this suspending function is invoked or while - * this function is waiting for dispatch, it resumes with a [CancellationException]. - * There is a **prompt cancellation guarantee**. If the job was cancelled while this function was - * suspended, it will not resume successfully. See [suspendCancellableCoroutine] documentation for low-level details. + * + * This suspending function is cancellable: if the [Job] of the current coroutine is cancelled or completed while + * [yield] is invoked or while waiting for dispatch, it immediately resumes with [CancellationException]. + * There is a **prompt cancellation guarantee**: even if this function is ready to return the result, but was cancelled + * while suspended, [CancellationException] will be thrown. See [suspendCancellableCoroutine] for low-level details. * * **Note**: This function always [checks for cancellation][ensureActive] even when it does not suspend. * diff --git a/kotlinx-coroutines-core/common/src/channels/Channel.kt b/kotlinx-coroutines-core/common/src/channels/Channel.kt index 9523634995..a42a2eb879 100644 --- a/kotlinx-coroutines-core/common/src/channels/Channel.kt +++ b/kotlinx-coroutines-core/common/src/channels/Channel.kt @@ -41,11 +41,12 @@ public interface SendChannel { * All elements sent over the channel are delivered in first-in first-out order. The sent element * will be delivered to receivers before the close token. * - * This suspending function is cancellable. If the [Job] of the current coroutine is cancelled or completed while this - * function is suspended, this function immediately resumes with a [CancellationException]. - * There is a **prompt cancellation guarantee**. If the job was cancelled while this function was - * suspended, it will not resume successfully. The `send` call can send the element to the channel, - * but then throw [CancellationException], thus an exception should not be treated as a failure to deliver the element. + * This suspending function is cancellable: if the [Job] of the current coroutine is cancelled or completed while this + * suspending function is waiting, this function immediately resumes with [CancellationException]. + * There is a **prompt cancellation guarantee**: even if [send] managed to send the element, but was cancelled + * while suspended, [CancellationException] will be thrown. See [suspendCancellableCoroutine] for low-level details. + * + * Because of the prompt cancellation guarantee, an exception does not always mean a failure to deliver the element. * See "Undelivered elements" section in [Channel] documentation for details on handling undelivered elements. * * Note that this function does not check for cancellation when it is not suspended. @@ -218,6 +219,15 @@ public interface ReceiveChannel { * but then throw [CancellationException], thus failing to deliver the element. * See "Undelivered elements" section in [Channel] documentation for details on handling undelivered elements. * + * This suspending function is cancellable: if the [Job] of the current coroutine is cancelled or completed while this + * suspending function is waiting, this function immediately resumes with [CancellationException]. + * There is a **prompt cancellation guarantee**: even if [receive] managed to retrieve the element from the channel, + * but was cancelled while suspended, [CancellationException] will be thrown. + * See [suspendCancellableCoroutine] for low-level details. + * + * Because of the prompt cancellation guarantee, some values retrieved from the channel can become lost. + * See "Undelivered elements" section in [Channel] documentation for details on handling undelivered elements. + * * Note that this function does not check for cancellation when it is not suspended. * Use [yield] or [CoroutineScope.isActive] to periodically check for cancellation in tight loops if needed. * @@ -240,11 +250,13 @@ public interface ReceiveChannel { * or the close cause if the channel was closed. Closed cause may be `null` if the channel was closed normally. * The result cannot be [failed][ChannelResult.isFailure] without being [closed][ChannelResult.isClosed]. * - * This suspending function is cancellable. If the [Job] of the current coroutine is cancelled or completed while this - * function is suspended, this function immediately resumes with a [CancellationException]. - * There is a **prompt cancellation guarantee**. If the job was cancelled while this function was - * suspended, it will not resume successfully. The `receiveCatching` call can retrieve the element from the channel, - * but then throw [CancellationException], thus failing to deliver the element. + * This suspending function is cancellable: if the [Job] of the current coroutine is cancelled or completed while this + * suspending function is waiting, this function immediately resumes with [CancellationException]. + * There is a **prompt cancellation guarantee**: even if [receiveCatching] managed to retrieve the element from the + * channel, but was cancelled while suspended, [CancellationException] will be thrown. + * See [suspendCancellableCoroutine] for low-level details. + * + * Because of the prompt cancellation guarantee, some values retrieved from the channel can become lost. * See "Undelivered elements" section in [Channel] documentation for details on handling undelivered elements. * * Note that this function does not check for cancellation when it is not suspended. @@ -561,11 +573,13 @@ public interface ChannelIterator { * This function retrieves and removes an element from this channel for the subsequent invocation * of [next]. * - * This suspending function is cancellable. If the [Job] of the current coroutine is cancelled or completed while this - * function is suspended, this function immediately resumes with a [CancellationException]. - * There is a **prompt cancellation guarantee**. If the job was cancelled while this function was - * suspended, it will not resume successfully. The `hasNext` call can retrieve the element from the channel, - * but then throw [CancellationException], thus failing to deliver the element. + * This suspending function is cancellable: if the [Job] of the current coroutine is cancelled or completed while this + * suspending function is waiting, this function immediately resumes with [CancellationException]. + * There is a **prompt cancellation guarantee**: even if [hasNext] retrieves the element from the channel during + * its operation, but was cancelled while suspended, [CancellationException] will be thrown. + * See [suspendCancellableCoroutine] for low-level details. + * + * Because of the prompt cancellation guarantee, some values retrieved from the channel can become lost. * See "Undelivered elements" section in [Channel] documentation for details on handling undelivered elements. * * Note that this function does not check for cancellation when it is not suspended. @@ -651,11 +665,10 @@ public interface ChannelIterator { * ### Prompt cancellation guarantee * * All suspending functions with channels provide **prompt cancellation guarantee**. - * If the job was cancelled while send or receive function was suspended, it will not resume successfully, - * but throws a [CancellationException]. - * With a single-threaded [dispatcher][CoroutineDispatcher] like [Dispatchers.Main] this gives a - * guarantee that if a piece code running in this thread cancels a [Job], then a coroutine running this job cannot - * resume successfully and continue to run, ensuring a prompt response to its cancellation. + * If the job was cancelled while send or receive function was suspended, it will not resume successfully, even if it + * already changed the channel's state, but throws a [CancellationException]. + * With a single-threaded [dispatcher][CoroutineDispatcher] like [Dispatchers.Main], this gives a + * guarantee that the coroutine promptly reacts to the cancellation of its [Job] and does not resume its execution. * * > **Prompt cancellation guarantee** for channel operations was added since `kotlinx.coroutines` version `1.4.0` * > and had replaced a channel-specific atomic-cancellation that was not consistent with other suspending functions. @@ -663,9 +676,9 @@ public interface ChannelIterator { * * ### Undelivered elements * - * As a result of a prompt cancellation guarantee, when a closeable resource - * (like open file or a handle to another native resource) is transferred via channel from one coroutine to another - * it can fail to be delivered and will be lost if either send or receive operations are cancelled in transit. + * As a result of the prompt cancellation guarantee, when a closeable resource + * (like open file or a handle to another native resource) is transferred via a channel from one coroutine to another, + * it can fail to be delivered and will be lost if the receiving operation is cancelled in transit. * * A `Channel()` constructor function has an `onUndeliveredElement` optional parameter. * When `onUndeliveredElement` parameter is set, the corresponding function is called once for each element diff --git a/kotlinx-coroutines-core/common/src/channels/Produce.kt b/kotlinx-coroutines-core/common/src/channels/Produce.kt index 85f1df5057..882b3a121e 100644 --- a/kotlinx-coroutines-core/common/src/channels/Produce.kt +++ b/kotlinx-coroutines-core/common/src/channels/Produce.kt @@ -22,9 +22,10 @@ public interface ProducerScope : CoroutineScope, SendChannel { * Suspends the current coroutine until the channel is either [closed][SendChannel.close] or [cancelled][ReceiveChannel.cancel] * and invokes the given [block] before resuming the coroutine. * - * This suspending function is cancellable. - * There is a **prompt cancellation guarantee**. If the job was cancelled while this function was - * suspended, it will not resume successfully. See [suspendCancellableCoroutine] documentation for low-level details. + * This suspending function is cancellable: if the [Job] of the current coroutine is cancelled or completed while this + * suspending function is waiting, this function immediately resumes with [CancellationException]. + * There is a **prompt cancellation guarantee**: even if this function is ready to return, but was cancelled + * while suspended, [CancellationException] will be thrown. See [suspendCancellableCoroutine] for low-level details. * * Note that when the producer channel is cancelled, this function resumes with a cancellation exception. * Therefore, in case of cancellation, no code after the call to this function will be executed. diff --git a/kotlinx-coroutines-core/common/src/selects/Select.kt b/kotlinx-coroutines-core/common/src/selects/Select.kt index 638cc312ed..d6fff1101c 100644 --- a/kotlinx-coroutines-core/common/src/selects/Select.kt +++ b/kotlinx-coroutines-core/common/src/selects/Select.kt @@ -38,10 +38,10 @@ import kotlin.jvm.* * | [ReceiveChannel] | [receiveCatching][ReceiveChannel.receiveCatching] | [onReceiveCatching][ReceiveChannel.onReceiveCatching] * | none | [delay] | [onTimeout][SelectBuilder.onTimeout] * - * This suspending function is cancellable. If the [Job] of the current coroutine is cancelled or completed while this - * function is suspended, this function immediately resumes with [CancellationException]. - * There is a **prompt cancellation guarantee**. If the job was cancelled while this function was - * suspended, it will not resume successfully. See [suspendCancellableCoroutine] documentation for low-level details. + * This suspending function is cancellable: if the [Job] of the current coroutine is cancelled or completed while this + * suspending function is waiting, this function immediately resumes with [CancellationException]. + * There is a **prompt cancellation guarantee**: even if this function is ready to return the result, but was cancelled + * while suspended, [CancellationException] will be thrown. See [suspendCancellableCoroutine] for low-level details. * * Note that this function does not check for cancellation when it is not suspended. * Use [yield] or [CoroutineScope.isActive] to periodically check for cancellation in tight loops if needed. diff --git a/kotlinx-coroutines-core/common/src/sync/Mutex.kt b/kotlinx-coroutines-core/common/src/sync/Mutex.kt index 2bdad8c1a5..da430ec1d4 100644 --- a/kotlinx-coroutines-core/common/src/sync/Mutex.kt +++ b/kotlinx-coroutines-core/common/src/sync/Mutex.kt @@ -40,10 +40,10 @@ public interface Mutex { /** * Locks this mutex, suspending caller until the lock is acquired (in other words, while the lock is held elsewhere). * - * This suspending function is cancellable. If the [Job] of the current coroutine is cancelled or completed while this - * function is suspended, this function immediately resumes with [CancellationException]. - * There is a **prompt cancellation guarantee**. If the job was cancelled while this function was - * suspended, it will not resume successfully. See [suspendCancellableCoroutine] documentation for low-level details. + * This suspending function is cancellable: if the [Job] of the current coroutine is cancelled or completed while this + * suspending function is waiting, this function immediately resumes with [CancellationException]. + * There is a **prompt cancellation guarantee**: even if this function is ready to return the result, but was cancelled + * while suspended, [CancellationException] will be thrown. See [suspendCancellableCoroutine] for low-level details. * This function releases the lock if it was already acquired by this function before the [CancellationException] * was thrown. * diff --git a/kotlinx-coroutines-core/common/src/sync/Semaphore.kt b/kotlinx-coroutines-core/common/src/sync/Semaphore.kt index 54d1efab31..88b50e0041 100644 --- a/kotlinx-coroutines-core/common/src/sync/Semaphore.kt +++ b/kotlinx-coroutines-core/common/src/sync/Semaphore.kt @@ -28,14 +28,14 @@ public interface Semaphore { * Acquires a permit from this semaphore, suspending until one is available. * All suspending acquirers are processed in first-in-first-out (FIFO) order. * - * This suspending function is cancellable. If the [Job] of the current coroutine is cancelled or completed while this - * function is suspended, this function immediately resumes with [CancellationException]. - * There is a **prompt cancellation guarantee**. If the job was cancelled while this function was - * suspended, it will not resume successfully. See [suspendCancellableCoroutine] documentation for low-level details. + * This suspending function is cancellable: if the [Job] of the current coroutine is cancelled or completed while this + * suspending function is waiting, this function immediately resumes with [CancellationException]. + * There is a **prompt cancellation guarantee**: even if this function is ready to return the result, but was cancelled + * while suspended, [CancellationException] will be thrown. See [suspendCancellableCoroutine] for low-level details. * This function releases the semaphore if it was already acquired by this function before the [CancellationException] * was thrown. * - * Note, that this function does not check for cancellation when it does not suspend. + * Note that this function does not check for cancellation when it does not suspend. * Use [CoroutineScope.isActive] or [CoroutineScope.ensureActive] to periodically * check for cancellation in tight loops if needed. * diff --git a/kotlinx-coroutines-core/js/src/Promise.kt b/kotlinx-coroutines-core/js/src/Promise.kt index fe4940e87e..fcf4cd025f 100644 --- a/kotlinx-coroutines-core/js/src/Promise.kt +++ b/kotlinx-coroutines-core/js/src/Promise.kt @@ -55,11 +55,10 @@ public fun Promise.asDeferred(): Deferred { /** * Awaits for completion of the promise without blocking. * - * This suspending function is cancellable. - * If the [Job] of the current coroutine is cancelled or completed while this suspending function is waiting, this function - * stops waiting for the promise and immediately resumes with [CancellationException]. - * There is a **prompt cancellation guarantee**. If the job was cancelled while this function was - * suspended, it will not resume successfully. See [suspendCancellableCoroutine] documentation for low-level details. + * This suspending function is cancellable: if the [Job] of the current coroutine is cancelled or completed while this + * suspending function is waiting on the promise, this function immediately resumes with [CancellationException]. + * There is a **prompt cancellation guarantee**: even if this function is ready to return the result, but was cancelled + * while suspended, [CancellationException] will be thrown. See [suspendCancellableCoroutine] for low-level details. */ public suspend fun Promise.await(): T = suspendCancellableCoroutine { cont: CancellableContinuation -> this@await.then( diff --git a/kotlinx-coroutines-core/wasmJs/src/Promise.kt b/kotlinx-coroutines-core/wasmJs/src/Promise.kt index 980f13867f..b26394440b 100644 --- a/kotlinx-coroutines-core/wasmJs/src/Promise.kt +++ b/kotlinx-coroutines-core/wasmJs/src/Promise.kt @@ -66,11 +66,10 @@ public fun Promise.asDeferred(): Deferred { /** * Awaits for completion of the promise without blocking. * - * This suspending function is cancellable. - * If the [Job] of the current coroutine is cancelled or completed while this suspending function is waiting, this function - * stops waiting for the promise and immediately resumes with [CancellationException]. - * There is a **prompt cancellation guarantee**. If the job was cancelled while this function was - * suspended, it will not resume successfully. See [suspendCancellableCoroutine] documentation for low-level details. + * This suspending function is cancellable: if the [Job] of the current coroutine is cancelled or completed while this + * suspending function is waiting on the promise, this function immediately resumes with [CancellationException]. + * There is a **prompt cancellation guarantee**: even if this function is ready to return the result, but was cancelled + * while suspended, [CancellationException] will be thrown. See [suspendCancellableCoroutine] for low-level details. */ @Suppress("UNCHECKED_CAST") public suspend fun Promise.await(): T = suspendCancellableCoroutine { cont: CancellableContinuation ->