Lost Illusion
11/25/2023, 11:17 AMlaunch {
launch { println("b") }
delay(5000}
}
Same result on Windows and the VPS. B is printed pretty much instantly.
Example B:
launch {
delay(1)
launch { println("b") }
delay(5000)
}
Output is pretty much the same as Example A on Windows. On the VPS, it takes about 5 seconds (or until it gets to the end of the block?) for B to be printed.
This becomes a problem when the delay(1) and inner-launch is replaced with actual logic, and inside of a loop... the inner launches will never start as it waits until the end of the block.
Any ideas?Sam
11/25/2023, 12:32 PMDaniel Pitts
11/25/2023, 3:42 PMephemient
11/25/2023, 4:35 PMlaunch(<http://Dispatchers.IO|Dispatchers.IO>)
may be blockingephemient
11/25/2023, 4:36 PMLost Illusion
11/25/2023, 7:32 PMsuspend fun main(): Unit = coroutineScope {
run()
}
suspend fun run() = coroutineScope {
val socket = javax.net.ServerSocketFactory.getDefault().createServerSocket(143)
println("start ${System.currentTimeMillis()}")
launch {
delay(1)
launch {
println("b ${System.currentTimeMillis()}")
}
socket.accept()
}
}
should I be wrapping the socket.accept() with a different context? this is how the code looks like not dumbed-down (minus abstractions) since it doesnt seem like there's a specific part causing it, rather a random thing. Here the launch block is never called.
coroutineScope {
while (isActive) {
val transport = socket.accept()
launch { handle(transport) }
}
}
Lost Illusion
11/25/2023, 7:56 PMashmelev
11/25/2023, 9:54 PMLost Illusion
11/25/2023, 10:21 PMashmelev
11/25/2023, 10:38 PMval serverSocket: Future<AsynchronousSocketChannel> = AsynchronousServerSocketChannel.open().bind(InetSocketAddress(123)).accept()
That returns a Future and should not blockashmelev
11/25/2023, 10:39 PMLost Illusion
11/25/2023, 11:05 PMLost Illusion
11/25/2023, 11:06 PMephemient
11/26/2023, 1:42 AMephemient
11/26/2023, 1:42 AMLost Illusion
11/26/2023, 3:21 PM