chrmelchior
06/01/2023, 11:57 AMwithTimeout
, it seems to prevent closing the dispatcher being used. Anyone have any ideas why it might not work? (The code is a simplified example of the real code)
@Test
fun nestedTimeouts() = runBlocking {
val disp: CloseableCoroutineDispatcher = newSingleThreadContext("my-test")
val result = withTimeout(30.seconds) {
withContext(disp) {
// Disabling the inner timeout will make it work correctly
withTimeout(30.seconds) {
"Hello"
}
}
}
println(result) // Print "Hello"
disp.close()
println("Dispatcher closed: $disp") // We never reach here if the inner timeout is enabled
}
It only deadlocks on Darwin, JVM platforms work fine 🤔Dmitry Khalanskiy [JB]
06/01/2023, 11:59 AMchrmelchior
06/01/2023, 12:01 PMchrmelchior
06/01/2023, 12:01 PMDmitry Khalanskiy [JB]
06/01/2023, 12:02 PMnewSingleThreadContext
quite a bit in 1.7.0, so maybe the issue is fixed already.Dmitry Khalanskiy [JB]
06/01/2023, 12:31 PMDmitry Khalanskiy [JB]
06/01/2023, 1:01 PMDmitry Khalanskiy [JB]
06/01/2023, 1:11 PMnewFixedThreadPool(1, "my-test")
instead.chrmelchior
06/01/2023, 1:15 PMnewSingleThreadContext
just seems to delegate to that?
public actual fun newSingleThreadContext(name: String): ExecutorCoroutineDispatcher =
newFixedThreadPoolContext(1, name)
Dmitry Khalanskiy [JB]
06/01/2023, 1:17 PMchrmelchior
06/01/2023, 1:18 PMchrmelchior
06/01/2023, 1:21 PM