I am facing an issue in using semaphores on iOS. I am implementing a feature to execute a series of async methods sequentially, one after another in order.
let semaphore = DispatchSemaphore(value: 1)
semaphore.wait()
performFirstTask {
semaphore.signal
}
semaphore.wait()
performSecondTask {
semaphore.signal
}
semaphore.wait()
performThirdTask {
semaphore.signal
}
So this is working as expected, but the issue comes if the user moves away from the screen in the wait state, so when the callback from a particular task fires, the view might have deallocated, which is causing a crash, Can anyone please help me to resolve this issue, I am not seeing any way to release the semaphores.
Thanks in advance
async await
, this stuff is over complicated and prone to bugs developer.apple.com/wwdc21/10132 – Pittel