Skip to content

Commit

Permalink
Implement SessionTask.State
Browse files Browse the repository at this point in the history
  • Loading branch information
cysp committed May 2, 2019
1 parent 341154c commit 0cc3eb1
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion Sources/DVR/SessionDataTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,20 @@ final class SessionDataTask: URLSessionDataTask {

// MARK: - URLSessionTask

var _state: URLSessionTask.State?
override var state: URLSessionTask.State {
return _state ?? .suspended
}

override func cancel() {
// Don't do anything
}

override func resume() {
let cassette = session.cassette

_state = .running

// Find interaction
if let interaction = session.cassette?.interactionForRequest(request) {
self.interaction = interaction
Expand All @@ -47,7 +54,15 @@ final class SessionDataTask: URLSessionDataTask {
completion(interaction.responseData, interaction.response, nil)
}
}
session.finishTask(self, interaction: interaction, playback: true)

queue.async { [weak self] in
guard let self = self else {
return
}

self._state = .completed
self.session.finishTask(self, interaction: interaction, playback: true)
}
return
}

Expand Down Expand Up @@ -76,6 +91,8 @@ final class SessionDataTask: URLSessionDataTask {
this.completion?(data, response, nil)
}

this._state = .completed

// Create interaction
this.interaction = Interaction(request: this.request, response: response, responseData: data)
this.session.finishTask(this, interaction: this.interaction!, playback: false)
Expand Down

0 comments on commit 0cc3eb1

Please sign in to comment.