forked from boldare/swift-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from MarekKojder/fix/sending-multiple-requests
Hot fix for sending multiple requests
- Loading branch information
Showing
21 changed files
with
1,069 additions
and
1,042 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// | ||
// ApiServiceTask.swift | ||
// RxSwiftAPI | ||
// | ||
// Created by Marek Kojder on 11/10/2019. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension ApiService.Task { | ||
|
||
/** | ||
Task Status | ||
- suspended: task is not running yer or is paused, | ||
- running: task is during execution, | ||
- finished: task has finished. | ||
*/ | ||
enum Status { | ||
case suspended | ||
case running | ||
case finished | ||
} | ||
} | ||
|
||
public extension ApiService { | ||
|
||
///Class which allows to manage request and follow its progress. | ||
final class Task { | ||
private let task: SessionService.Task | ||
|
||
///Current Status of task | ||
public var status: Status { | ||
switch task.status { | ||
case .suspended: | ||
return .suspended | ||
case .running: | ||
return .running | ||
case .finishing, | ||
.finished: | ||
return .finished | ||
} | ||
} | ||
|
||
///A representation of the overall task progress. | ||
public var progress: Progress { | ||
return task.progress | ||
} | ||
|
||
internal init(_ task: SessionService.Task) { | ||
self.task = task | ||
} | ||
} | ||
} | ||
|
||
public extension ApiService.Task { | ||
|
||
///Resumes the task, if it is suspended. | ||
func resume() { | ||
task.resume() | ||
} | ||
|
||
///Temporarily suspends a task. | ||
func suspend() { | ||
task.suspend() | ||
} | ||
|
||
///Cancels the task. | ||
func cancel() { | ||
task.cancel() | ||
} | ||
} | ||
|
||
extension ApiService.Task: Equatable { | ||
public static func == (lhs: ApiService.Task, rhs: ApiService.Task) -> Bool { | ||
return lhs.task == rhs.task | ||
} | ||
} | ||
|
||
extension ApiService.Task: Hashable { | ||
public func hash(into hasher: inout Hasher) { | ||
hasher.combine(task) | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.