Skip to content

Commit

Permalink
Progress is now working properly
Browse files Browse the repository at this point in the history
  • Loading branch information
wpK committed Sep 26, 2017
1 parent 3554952 commit c0a001c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions Sources/Apollo/SessionDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ class SessionDelegate: NSObject {
self.tasks[task.taskIdentifier] = SessionDelegateTask(completionHandler: completionHandler, progressHandler: progressHandler)
}

func get(task: URLSessionTask) -> SessionDelegateTask? {
fileprivate func get(task: URLSessionTask) -> SessionDelegateTask? {
return lock.withLock {
return self.tasks[task.taskIdentifier]
}
}

func remove(task: URLSessionTask) {
fileprivate func remove(task: URLSessionTask) {
self.lock.lock()
defer { self.lock.unlock() }

Expand All @@ -47,7 +47,8 @@ extension SessionDelegate: URLSessionDataDelegate {
extension SessionDelegate: URLSessionTaskDelegate {
func urlSession(_ session: URLSession, task: URLSessionTask, didSendBodyData bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) {
if let sessionTask = self.get(task: task), let progressHandler = sessionTask.progressHandler {
progressHandler(Progress((totalBytesSent/totalBytesExpectedToSend)) * 100)
let progress = Float(totalBytesSent)/Float(totalBytesExpectedToSend)
progressHandler(Progress(progress * 100))
}
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/ApolloTestSupport/MockNetworkTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public final class MockNetworkTransport: NetworkTransport {
self.body = body
}

public func send<Operation:>(operation: Operation, completionHandler: @escaping (GraphQLResponse<Operation>?, Error?) -> Void) -> Cancellable {
public func send<Operation>(operation: Operation, completionHandler: @escaping (GraphQLResponse<Operation>?, Error?) -> Void) -> Cancellable {
DispatchQueue.global(qos: .default).async {
completionHandler(GraphQLResponse(operation: operation, body: self.body), nil)
}
Expand Down

0 comments on commit c0a001c

Please sign in to comment.