From 5f3135de6c9b6d6620e10d36542641441a470af6 Mon Sep 17 00:00:00 2001 From: Scott Talbot Date: Fri, 3 May 2019 16:31:48 +1000 Subject: [PATCH] Call completion after delegate methods --- Sources/DVR/SessionDataTask.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/DVR/SessionDataTask.swift b/Sources/DVR/SessionDataTask.swift index 8afa464..7a2a9ac 100644 --- a/Sources/DVR/SessionDataTask.swift +++ b/Sources/DVR/SessionDataTask.swift @@ -53,13 +53,13 @@ final class SessionDataTask: URLSessionDataTask { fatalError("[DVR] Something has gone horribly wrong.") } + self._state = .completed + self.session.finishTask(self, interaction: interaction, playback: true) + // Forward completion if let completion = self.completion { completion(interaction.responseData, interaction.response, nil) } - - self._state = .completed - self.session.finishTask(self, interaction: interaction, playback: true) } return } @@ -90,13 +90,13 @@ final class SessionDataTask: URLSessionDataTask { fatalError("[DVR] Something has gone horribly wrong.") } - self.completion?(data, response, nil) - self._state = .completed // Create interaction self.interaction = Interaction(request: self.request, response: response, responseData: data) self.session.finishTask(self, interaction: self.interaction!, playback: false) + + self.completion?(data, response, nil) } }) task.resume()