From 9ce441e578b87f9cde2f35d3c67ad4053f683bd8 Mon Sep 17 00:00:00 2001 From: Dasmer Singh Date: Mon, 21 Sep 2015 14:17:41 -0400 Subject: [PATCH 1/2] SessionDataTask's resume does work on a new background thread as opposed to the calling thread, in order to better mimic NSURLSessionDataTask functionality --- DVR/SessionDataTask.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/DVR/SessionDataTask.swift b/DVR/SessionDataTask.swift index 2757166..d64aafc 100644 --- a/DVR/SessionDataTask.swift +++ b/DVR/SessionDataTask.swift @@ -35,7 +35,12 @@ class SessionDataTask: NSURLSessionDataTask { // Find interaction if let interaction = cassette?.interactionForRequest(request) { // Forward completion - completion?(interaction.responseData, interaction.response, nil) + if let completion = completion { + let queue = dispatch_queue_create("com.venmo.DVR.sessionDataTaskQueue", nil) + dispatch_async(queue) { + completion(interaction.responseData, interaction.response, nil) + } + } return } From 0262a8640bdc5967616c7d57e59b7619e57433b5 Mon Sep 17 00:00:00 2001 From: Dasmer Singh Date: Mon, 21 Sep 2015 15:31:44 -0400 Subject: [PATCH 2/2] Makes a session manage only one queue for its lifetime --- DVR/SessionDataTask.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DVR/SessionDataTask.swift b/DVR/SessionDataTask.swift index d64aafc..a620dd0 100644 --- a/DVR/SessionDataTask.swift +++ b/DVR/SessionDataTask.swift @@ -12,6 +12,7 @@ class SessionDataTask: NSURLSessionDataTask { weak var session: Session! let request: NSURLRequest let completion: Completion? + private let queue = dispatch_queue_create("com.venmo.DVR.sessionDataTaskQueue", nil) // MARK: - Initializers @@ -36,7 +37,6 @@ class SessionDataTask: NSURLSessionDataTask { if let interaction = cassette?.interactionForRequest(request) { // Forward completion if let completion = completion { - let queue = dispatch_queue_create("com.venmo.DVR.sessionDataTaskQueue", nil) dispatch_async(queue) { completion(interaction.responseData, interaction.response, nil) }