GeezerVison is showing github.com — Refactor: use runloop instead of NSOperationQueue. · kevin-lyn/STNetTaskQueue@aa430a5
File tree
Expand file treeCollapse file tree
Open diff view settings
STNetTaskQueueTest.xcodeproj
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: STNetTaskQueue/STHTTPNetTaskQueueHandler.m +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -84,7 +84,7 @@ - (instancetype)initWithBaseURL:(NSURL *)baseURL configuration:(NSURLSessionConf |
84 | 84 | return self; |
85 | 85 | } |
86 | 86 |
|
87 | | -- (void)netTaskQueue:(STNetTaskQueue *)netTaskQueue task:(STNetTask *)task taskId:(int)taskId |
| 87 | +- (void)netTaskQueue:(STNetTaskQueue *)netTaskQueue handleTask:(STNetTask *)task |
88 | 88 | { |
89 | 89 | NSAssert([task isKindOfClass:[STHTTPNetTask class]], @"Net task should be subclass of STHTTPNetTask"); |
90 | 90 |
|
@@ -151,10 +151,10 @@ - (void)netTaskQueue:(STNetTaskQueue *)netTaskQueue task:(STNetTask *)task taskI |
151 | 151 | } |
152 | 152 |
|
153 | 153 | if (error) { |
154 | | - [netTaskQueue didFailWithError:error taskId:taskId]; |
| 154 | + [netTaskQueue task:task didFailWithError:error]; |
155 | 155 | } |
156 | 156 | else { |
157 | | - [netTaskQueue didResponse:responseObj taskId:taskId]; |
| 157 | + [netTaskQueue task:task didResponse:responseObj]; |
158 | 158 | } |
159 | 159 | } |
160 | 160 | else { |
@@ -165,7 +165,7 @@ - (void)netTaskQueue:(STNetTaskQueue *)netTaskQueue task:(STNetTask *)task taskI |
165 | 165 | STHTTPNetTaskErrorResponseDataUserInfoKey: data }]; |
166 | 166 | [STNetTaskQueueLog log:@"HTTP error with url: %@\nMethod: %@\nPayload: %@", httpResponse.URL.absoluteString, _methodMap[@(httpTask.method)], parameters]; |
167 | 167 | } |
168 | | - [netTaskQueue didFailWithError:error taskId:taskId]; |
| 168 | + [netTaskQueue task:task didFailWithError:error]; |
169 | 169 | } |
170 | 170 | }; |
171 | 171 |
|
|
Collapse file
Copy file name to clipboardExpand all lines: STNetTaskQueue/STNetTask.h +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -31,10 +31,10 @@ FOUNDATION_EXPORT NSString *const STNetTaskUnknownError; |
31 | 31 |
|
32 | 32 | @interface STNetTask : NSObject |
33 | 33 |
|
34 | | -@property (nonatomic, strong) NSError *error; |
35 | | -@property (nonatomic, assign) BOOL pending; |
36 | | -@property (nonatomic, assign) BOOL finished; |
37 | | -@property (nonatomic, assign) NSUInteger retryCount; |
| 34 | +@property (atomic, strong) NSError *error; |
| 35 | +@property (atomic, assign) BOOL pending; |
| 36 | +@property (atomic, assign) BOOL finished; |
| 37 | +@property (atomic, assign) NSUInteger retryCount; |
38 | 38 |
|
39 | 39 | - (NSString *)uri; |
40 | 40 | - (void)didResponse:(id)response; |
|
Collapse file
Copy file name to clipboardExpand all lines: STNetTaskQueue/STNetTaskQueue.h +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
13 | 13 |
|
14 | 14 | @protocol STNetTaskQueueHandler <NSObject> |
15 | 15 |
|
16 | | -- (void)netTaskQueue:(STNetTaskQueue *)netTaskQueue task:(STNetTask *)task taskId:(int)taskId; |
| 16 | +- (void)netTaskQueue:(STNetTaskQueue *)netTaskQueue handleTask:(STNetTask *)task; |
17 | 17 |
|
18 | 18 | @end |
19 | 19 |
|
|
32 | 32 | - (void)cancelTask:(STNetTask *)task; |
33 | 33 |
|
34 | 34 | // Only used in "STNetTaskQueueHandler". |
35 | | -- (void)didResponse:(id)response taskId:(int)taskId; |
36 | | -- (void)didFailWithError:(NSError *)error taskId:(int)taskId; |
| 35 | +- (void)task:(STNetTask *)task didResponse:(id)response; |
| 36 | +- (void)task:(STNetTask *)task didFailWithError:(NSError *)error; |
37 | 37 |
|
38 | 38 | // Add a task delegate to "STNetTaskQueue", |
39 | 39 | // it's a weak reference and adding duplicated delegate with same uri will be ignored. |
|