halim
04/18/2019, 11:47 AMsuspend fun ServerSocket.listening() = suspendCancellableCoroutine<Socket>{
it.invokeOnClancellation { println("coroutine is cancelling...."); close() }
it.resueWith(Result.success(accpet())
}
fun main() = runBlocking() {
withTimeout(3000) {
val socket = ServerSocket(4000).run { listening() }
}
}
i expected to cancel after 3 sec but not think happen, server still listening and wait for client to connect
why suspendCancellableCoroutine not cancelled ?? any ideatseisel
04/18/2019, 12:32 PMaccept
in a withContext(<http://Dispatchers.IO|Dispatchers.IO>)
block) to prevent from blocking the main threadhalim
04/18/2019, 2:01 PMgildor
04/18/2019, 4:27 PMhalim
04/21/2019, 8:51 AM