File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed
Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,9 @@ FOUNDATION_EXPORT NSString *const STNetTaskUnknownError;
1818 [subscriber sendNext: TASK];\
1919 [subscriber sendCompleted ]; \
2020 }]; \
21+ [[[[RACObserve (TASK, cancelled) skip: 1 ] ignore: @NO ] deliverOnMainThread ] subscribeNext: ^(id x) { \
22+ [subscriber sendError: nil ];\
23+ }]; \
2124 return nil ; \
2225}]
2326#endif
@@ -47,6 +50,12 @@ FOUNDATION_EXPORT NSString *const STNetTaskUnknownError;
4750 */
4851@property (atomic , assign ) BOOL pending;
4952
53+ /*
54+ Indicates if the net task is cancelled.
55+ This value would be "NO" by default after net task is created, even the net task is not added to queue.
56+ */
57+ @property (atomic , assign ) BOOL cancelled;
58+
5059/* Indicates if the net task is finished(no matter it's successful or failed). */
5160@property (atomic , assign ) BOOL finished;
5261
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ - (void)performUsingBlock:(void(^)())block
7373- (void )addTask : (STNetTask *)task
7474{
7575 NSAssert (self.handler, @" STNetTaskQueueHandler is not set." );
76- NSAssert (!task.finished, @" STNetTask is finished, please recreate a net task." );
76+ NSAssert (!task.finished && !task.cancelled , @" STNetTask is finished/cancelled , please recreate a net task." );
7777
7878 task.pending = YES ;
7979 [self performInThread: self .thred usingBlock: ^{
@@ -110,6 +110,7 @@ - (void)_cancelTask:(STNetTask *)task
110110 task.pending = NO ;
111111
112112 [self .handler netTaskQueue: self didCancelTask: task];
113+ task.cancelled = YES ;
113114}
114115
115116- (BOOL )_retryTask : (STNetTask *)task withError : (NSError *)error
You can’t perform that action at this time.
0 commit comments