The map operation for sequence of ips doesn’t compute the next result until it is requested by forEach.
So the order of processing is following: map starts async operation for the first ip, then forEach awaits it. Then map starts async ping for the second ip and so on.
Ok, I agree.
But if I remove asSequence() then the ping function will still be executed sequentially.
How to make this code run 4 processes with a ping command in parallel?
By default runBlocking doesn’t use any dispatches, so does async function started in the scope of runBlocking, thus each coroutine is dispatched to an event loop in the single thread.
You can specify a dispatcher with the context parameter either in runBlocking or in async, e.g.