Hi, I just want to know how to wait until the other work finishes/invalidated. In my case, I am using below code
class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
Task.detached(priority: .userInitiated) {
await self.runTask()
print("Finished")
}
}
func runTask() async {
let semaphore = DispatchSemaphore(value: 0)
DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
print("Singaling")
semaphore.signal()
}
semaphore.wait()
print("WAIT...")
}
}
Currently the semaphore.signal()
not called and semaphore.wait()
blocks main thread so the app is just hanged. I want to achive similar thing without blocking main thread.
Is there any solution? Thanking you!