I call some function in another thread:
dispatch_async(dispatch_get_global_queue(priority, 0)) {
self.someFunction()
}
Then in this function i want do synchronous request:
let config = NSURLSessionConfiguration.defaultSessionConfiguration()
let session = NSURLSession(configuration: config)
let dataSemaphore = dispatch_semaphore_create(0)
let task = session.dataTaskWithRequest(urlRequest, completionHandler: { (data, response, error) in
guard let responseData = data else {
print("Error: did not receive data")
return
}
guard error == nil else {
print("error calling GET")
print(error)
return
}
print("ASYNC")
})
task.resume()
dispatch_semaphore_wait(dataSemaphore, DISPATCH_TIME_FOREVER)
print("SYNC")
But thread stops dispatch_semaphore_wait(dataSemaphore, DISPATCH_TIME_FOREVER)
at this line