I have a data sync which should happen in a background thread in a sequential order as one task need to finish prior start syncing the next. I tried executing in a Dispatch queue. But then as the process scheduler decides what to execute first i ran in to lots of issues. My partial code as bellow.
DispatchQueue.main.async(execute: {
SyncAgent.shared.initDataSync()
})
func initDataSync() {
//These are not executing in the order. My objective is to make this happen sequentially in the background and notify the relevant screens once its completed.
syncUsers()
syncDevices()
syncAccouts()
syncLocations()
}