import Dispatch
import Foundation
DispatchQueue.main.async {
print("just print in main async")
}
RunLoop.current.run(mode: .default, before: .distantFuture)
print("RunLoop.current.run ends!")
If the runLoop ends after printing "just print in main async", does it means that the runLoop was terminated by main.async (just like an UI event)?
I want to know what exactly happens in this case.



Yes, I think in the provided code, the run loop will end after printing "just print in main async" because of the
DispatchQueue.main.asyncblock.As run loop will simply wait for events indefinitely (until an event occurs, because you have provided
.distantFuture).At some point, an event occurs, which can be a user interaction event (UI event) or another source getting processed. This event will interrupt the run loop and allow the scheduled
DispatchQueue.main.asyncblock to execute on the main queue.Then "just print in main async" will be printed from the asynchronously executed block.
However, after the printed statement there are no more events scheduled, so the run loop will eventually exit and print "RunLoop.current.run ends!".
And hope this link helps, too.