File tree 2 files changed +18
-1
lines changed
kotlinx-coroutines-core/jvm 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -205,7 +205,7 @@ private class CancelFutureOnCancel(private val future: Future<*>) : CancelHandle
205
205
override fun invoke (cause : Throwable ? ) {
206
206
// Don't interrupt when cancelling future on completion, because no one is going to reset this
207
207
// interruption flag and it will cause spurious failures elsewhere
208
- if (cause != null ) future.cancel(false )
208
+ future.cancel(false )
209
209
}
210
210
override fun toString () = " CancelFutureOnCancel[$future ]"
211
211
}
Original file line number Diff line number Diff line change @@ -38,4 +38,21 @@ class ExecutorAsCoroutineDispatcherDelayTest : TestBase() {
38
38
executor.shutdown()
39
39
assertEquals(1 , callsToSchedule)
40
40
}
41
+
42
+ @Test
43
+ fun testCancelling () = runTest {
44
+ val executor = STPE ()
45
+ launch(start = CoroutineStart .UNDISPATCHED ) {
46
+ suspendCancellableCoroutine<Unit > { cont ->
47
+ expect(1 )
48
+ (executor.asCoroutineDispatcher() as Delay ).scheduleResumeAfterDelay(1_000_000 , cont)
49
+ cont.cancel()
50
+ expect(2 )
51
+ }
52
+ }
53
+ expect(3 )
54
+ assertTrue(executor.getQueue().isEmpty())
55
+ executor.shutdown()
56
+ finish(4 )
57
+ }
41
58
}
You can’t perform that action at this time.
0 commit comments