Jonathan Walsh
08/06/2019, 4:24 PMsuspendCoroutine
within a withTimeout
call, but the timeout doesn't seem to work. Has anyone run into similar issues?Jonathan Walsh
08/06/2019, 4:24 PMThread.sleep
the timeout looks to just be completely ignored
assertFailsWith(TimeoutCancellationException::class) {
runBlocking {
// this timeout is ignored
withTimeout(100) {
suspendCoroutine<Boolean> { cont ->
Thread.sleep(150)
cont.resume(true)
}
}
}
}
Jonathan Walsh
08/06/2019, 4:25 PMlaunch
and delay
the timeout is still ignored but the original execution never resumesJonathan Walsh
08/06/2019, 4:25 PMassertFailsWith(TimeoutCancellationException::class) {
runBlocking {
withTimeout(100) {
suspendCoroutine<Boolean> { cont ->
launch {
delay(150)
cont.resume(true)
}
}
}
}
}
louiscad
08/06/2019, 4:35 PMsuspendCoroutine
if you want the function to be cancellable. Use suspendCancellableCoroutine
instead.louiscad
08/06/2019, 4:36 PMlouiscad
08/06/2019, 4:36 PMThread.sleep
to be cancellable.Jonathan Walsh
08/06/2019, 5:38 PMsuspendCancellableCoroutine
, that works. Thanksgildor
08/06/2019, 11:15 PM