In this case I have to consider the asynchronous callback
as part of the task. I want only one task running at the same time.
Here is boilerplate:
func queueATask() {
DispatchQueue.main.async {
doSomeHeavyWorkPartA()
//tunnelProvider is an instance of NETunnelProviderManager
tunnelProvider.saveToPreferences {
continueHeavyWorkPartB()
}
}
}
So I can make multiple calls of this function.But still before running a new task,the previous one must be finished (including partA and PartB).
queueATask()
queueATask()
queueATask()
I was considering DispatchGroup
and DispatchSemaphore
, but it needs to block the main queue which is not viable? All the tasks must be running in the main queue. If there is no partB callback block it would be much easier, I think this is the hard part for this situation.
Kindly guide me how to solve this issue.
Thanks