Skip to content

Commit

Permalink
Removing extraneous dispatch to background and using weak reference f…
Browse files Browse the repository at this point in the history
…or delegate in response
  • Loading branch information
mattt committed Oct 7, 2014
1 parent cb8439e commit 80a4f7d
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions Source/Alamofire.swift
Original file line number Diff line number Diff line change
Expand Up @@ -626,15 +626,14 @@ public class Request {
:returns: The request.
*/
public func response(priority: Int = DISPATCH_QUEUE_PRIORITY_DEFAULT, queue: dispatch_queue_t? = nil, serializer: Serializer, completionHandler: (NSURLRequest, NSHTTPURLResponse?, AnyObject?, NSError?) -> Void) -> Self {
dispatch_async(delegate.queue, {
dispatch_async(dispatch_get_global_queue(priority, 0), {
let (responseObject: AnyObject?, serializationError: NSError?) = serializer(self.request, self.response, self.delegate.data)

dispatch_async(queue ?? dispatch_get_main_queue(), {
completionHandler(self.request, self.response, responseObject, self.delegate.error ?? serializationError)
})
})
})
let delegate = self.delegate
dispatch_async(delegate.queue) { [weak delegate] in
let (responseObject: AnyObject?, serializationError: NSError?) = serializer(self.request, self.response, delegate?.data)

dispatch_async(queue ?? dispatch_get_main_queue()) {
completionHandler(self.request, self.response, responseObject, delegate?.error ?? serializationError)
}
}

return self
}
Expand Down

0 comments on commit 80a4f7d

Please sign in to comment.