I perform URLSession.shared.downloadTask
request, but would like to execute code on the same thread the downloadTask
was executed on. For example:
func sample() {
let thread = Thread.current
URLSession.shared.downloadTask(with: file) {
someFunc() //How to execute on thread variable?
}.resume()
}
In the downloadTask
completion handler, it is running on a background thread. However, I'd like to call someFunc()
on the same thread sample()
was called on. How do I do something like Thread.current.async {...}
so I can do this:
func sample() {
let thread = Thread.current
URLSession.shared.downloadTask(with: file) {
thread.async { someFunc() } //Doesn't compile
}.resume()
}