Avatar
Avatar
omochimetaru
@swift-5.6.3 -Xfrontend -parse-as-library import Foundation func nonIsolatedFunc() async { Thread.sleep(forTimeInterval: 1) } actor A { func isolatedFunc() async { let begin = Date() print("begin") for _ in 0..<32 { Task { await nonIsolatedFunc() } } Thread.sleep(forTimeInterval: 1) await Task.yield() let dur = Date().timeIntervalSince(begin) print("end \(dur)") } } @main struct Main { @MainActor static func main() async { await A().isolatedFunc() } }
begin end 4.000761032104492