diff options
author | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2014-02-23 18:15:23 -0800 |
---|---|---|
committer | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2014-02-23 18:15:23 -0800 |
commit | 2198484458e887ec3c7c0e15497c81f52dba5619 (patch) | |
tree | 6e6a0b188c7ba8993a81b999d2dc94eb0eb74995 | |
parent | 2b03e94aac54808afb2ad838c449f0e2d058849b (diff) |
Fixed #608: cancelled scheduled operations that are not run will not run in the future.
-rw-r--r-- | src/core/basetypes/MCOperation.cc | 11 | ||||
-rw-r--r-- | src/core/basetypes/MCOperation.h | 4 | ||||
-rw-r--r-- | src/core/basetypes/MCOperationQueue.cc | 4 | ||||
-rw-r--r-- | src/objc/utils/MCOOperation.h | 4 | ||||
-rw-r--r-- | src/objc/utils/MCOOperation.mm | 1 |
5 files changed, 22 insertions, 2 deletions
diff --git a/src/core/basetypes/MCOperation.cc b/src/core/basetypes/MCOperation.cc index b6848d78..71b3c52f 100644 --- a/src/core/basetypes/MCOperation.cc +++ b/src/core/basetypes/MCOperation.cc @@ -6,6 +6,7 @@ Operation::Operation() { mCallback = NULL; mCancelled = false; + mShouldRunWhenCancelled = false; pthread_mutex_init(&mLock, NULL); #if __APPLE__ mCallbackDispatchQueue = dispatch_get_main_queue(); @@ -43,6 +44,16 @@ bool Operation::isCancelled() return value; } +bool Operation::shouldRunWhenCancelled() +{ + return mShouldRunWhenCancelled; +} + +void Operation::setShouldRunWhenCancelled(bool shouldRunWhenCancelled) +{ + mShouldRunWhenCancelled = shouldRunWhenCancelled; +} + void Operation::beforeMain() { } diff --git a/src/core/basetypes/MCOperation.h b/src/core/basetypes/MCOperation.h index 6916caa3..b9d5f95e 100644 --- a/src/core/basetypes/MCOperation.h +++ b/src/core/basetypes/MCOperation.h @@ -38,9 +38,13 @@ namespace mailcore { #endif void performMethodOnCallbackThread(Method method, void * context, bool waitUntilDone = false); + virtual bool shouldRunWhenCancelled(); + virtual void setShouldRunWhenCancelled(bool shouldRunWhenCancelled); + private: OperationCallback * mCallback; bool mCancelled; + bool mShouldRunWhenCancelled; pthread_mutex_t mLock; #ifdef __APPLE__ dispatch_queue_t mCallbackDispatchQueue; diff --git a/src/core/basetypes/MCOperationQueue.cc b/src/core/basetypes/MCOperationQueue.cc index 76a76bc7..73b62f19 100644 --- a/src/core/basetypes/MCOperationQueue.cc +++ b/src/core/basetypes/MCOperationQueue.cc @@ -93,7 +93,9 @@ void OperationQueue::runOperations() performOnCallbackThread(op, (Object::Method) &OperationQueue::beforeMain, op, true); - op->main(); + if (!op->isCancelled() || op->shouldRunWhenCancelled()) { + op->main(); + } op->retain()->autorelease(); diff --git a/src/objc/utils/MCOOperation.h b/src/objc/utils/MCOOperation.h index 263d4a46..f46536c9 100644 --- a/src/objc/utils/MCOOperation.h +++ b/src/objc/utils/MCOOperation.h @@ -17,6 +17,9 @@ /** Returns whether the operation is cancelled.*/ @property (readonly) BOOL isCancelled; +/** Returns whether the operation should run even if it's cancelled.*/ +@property (nonatomic, assign) BOOL shouldRunWhenCancelled; + /** The queue this operation dispatches the callback on. Defaults to the main queue. This property should be used only if there's performance issue creating or calling the callback in the main thread. */ @@ -29,7 +32,6 @@ /** Cancel the operation.*/ - (void) cancel; - @end #endif diff --git a/src/objc/utils/MCOOperation.mm b/src/objc/utils/MCOOperation.mm index 7502afae..cabb9a61 100644 --- a/src/objc/utils/MCOOperation.mm +++ b/src/objc/utils/MCOOperation.mm @@ -82,6 +82,7 @@ public: } MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setCallbackDispatchQueue, callbackDispatchQueue); +MCO_OBJC_SYNTHESIZE_SCALAR(BOOL, bool, setShouldRunWhenCancelled, shouldRunWhenCancelled); - (void) cancel { |