Let's say I queue some tasks on DispatchQueue.global() and then switch to another app or locking screen for a while. The app was not terminated but stayed in the background.
Is there a chance that some tasks queued but not yet start could be discarded, even if the app hasn’t been terminated, after switching to another app or locking the screen for a while?
Is there a chance that could be discarded, even if the app hasn’t been terminated, after switching to another app or locking the screen for a while?
No.
Dispatch queues are an in-memory construct. They continue to function across suspend and resume. Things will only get ‘lost’ if your process is terminated, which removes your app from memory.
Of course, if your app is suspended then the system is free to terminate it at any time. It usually does this when the device is under memory pressure, but there are lots of other reasons this can happen.
Finally, I recommend against using Dispatch global concurrent queues. See Avoid Dispatch Global Concurrent Queues for an explanation as to why. However, this issue, and my answer, is the same regardless of what queue type you use.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"