File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed
kotlinx-coroutines-core/jvm/src Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change 1
1
package kotlinx.coroutines
2
2
3
- import kotlinx.coroutines.flow.*
4
3
import kotlinx.coroutines.internal.*
5
4
import java.io.Closeable
6
5
import java.util.concurrent.*
@@ -145,7 +144,7 @@ internal class ExecutorCoroutineDispatcherImpl(override val executor: Executor)
145
144
)
146
145
// If everything went fine and the scheduling attempt was not rejected -- use it
147
146
if (future != null ) {
148
- continuation.cancelFutureOnCancellation( future)
147
+ continuation.invokeOnCancellation( CancelFutureOnCancel ( future) )
149
148
return
150
149
}
151
150
// Otherwise fallback to default executor
@@ -201,3 +200,12 @@ private class DisposableFutureHandle(private val future: Future<*>) : Disposable
201
200
}
202
201
override fun toString (): String = " DisposableFutureHandle[$future ]"
203
202
}
203
+
204
+ private class CancelFutureOnCancel (private val future : Future <* >) : CancelHandler {
205
+ override fun invoke (cause : Throwable ? ) {
206
+ // Don't interrupt when cancelling future on completion, because no one is going to reset this
207
+ // interruption flag and it will cause spurious failures elsewhere
208
+ if (cause != null ) future.cancel(false )
209
+ }
210
+ override fun toString () = " CancelFutureOnCancel[$future ]"
211
+ }
Original file line number Diff line number Diff line change @@ -12,10 +12,15 @@ import java.util.concurrent.*
12
12
* invokeOnCancellation { if (it != null) future.cancel(false) }
13
13
* ```
14
14
*/
15
+ @Deprecated(
16
+ " This function does not do what its name implies: it will not cancel the future if just cancel() was called." ,
17
+ level = DeprecationLevel .WARNING ,
18
+ replaceWith = ReplaceWith (" this.invokeOnCancellation { future.cancel(false) }" )
19
+ )
15
20
public fun CancellableContinuation <* >.cancelFutureOnCancellation (future : Future <* >): Unit =
16
- invokeOnCancellation(handler = CancelFutureOnCancel (future))
21
+ invokeOnCancellation(handler = PublicCancelFutureOnCancel (future))
17
22
18
- private class CancelFutureOnCancel (private val future : Future <* >) : CancelHandler {
23
+ private class PublicCancelFutureOnCancel (private val future : Future <* >) : CancelHandler {
19
24
override fun invoke (cause : Throwable ? ) {
20
25
// Don't interrupt when cancelling future on completion, because no one is going to reset this
21
26
// interruption flag and it will cause spurious failures elsewhere
You can’t perform that action at this time.
0 commit comments