Skip to content

Commit c25896b

Browse files
committed
Switched over to using in the operation subclass
1 parent f91741c commit c25896b

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

NetworkingInOperations-Example/Data/Abstract/ConcurrentOperation.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,16 @@ class ConcurrentOperation<T>: Operation {
6262
// MARK: - Control
6363

6464
override func start() {
65-
super.start()
65+
guard !isCancelled else {
66+
finish()
67+
return
68+
}
6669

6770
if !isExecuting {
6871
state = .executing
6972
}
73+
74+
main()
7075
}
7176

7277
func finish() {
@@ -77,8 +82,10 @@ class ConcurrentOperation<T>: Operation {
7782

7883
func complete(result: DataRequestResult<T>) {
7984
finish()
80-
81-
completionHandler?(result)
85+
86+
if !isCancelled {
87+
completionHandler?(result)
88+
}
8289
}
8390

8491
override func cancel() {

NetworkingInOperations-Example/Data/Managers/Questions/Operations/QuestionsRetrievalOperation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ class QuestionsRetrievalOperation: ConcurrentOperation<QuestionPage> {
2323
self.urlRequestFactory = urlRequestFactory
2424
}
2525

26-
// MARK: - Start
26+
// MARK: - Main
2727

28-
override func start() {
28+
override func main() {
2929
let urlRequest = urlRequestFactory.requestToRetrieveQuestions(pageIndex: pageIndex)
3030

3131
task = session.dataTask(with: urlRequest) { (data, response, error) in

NetworkingInOperations-Example/Data/Managers/User/Operations/AvatarRetrievalOperation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ class AvatarRetrievalOperation: ConcurrentOperation<(User, UIImage)> {
2222
self.user = user
2323
}
2424

25-
// MARK: - Start
25+
// MARK: - Main
2626

27-
override func start() {
27+
override func main() {
2828
guard let avatarURL = URL(string: user.avatarURL) else {
2929
cancel()
3030
return

0 commit comments

Comments
 (0)