2 * Copyright (c) 2017 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 #ifndef CKKSGroupOperation_h
26 #define CKKSGroupOperation_h
28 #import <Foundation/Foundation.h>
29 #include <dispatch/dispatch.h>
33 @interface
NSOperation (CKKSUsefulPrintingOperation
)
34 - (NSString
*)description
;
37 // If op is nonnull, op becomes a dependency of this operation
38 - (void)addNullableDependency
: (NSOperation
*) op
;
40 // Add all operations in this collection as dependencies, then add yourself to the collection
41 -(void)linearDependencies
:(NSHashTable
*)collection
;
44 @interface
NSBlockOperation (CKKSUsefulConstructorOperation
)
45 +(instancetype
)named
: (NSString
*)name withBlock
: (void(^)(void)) block
;
49 #define CKKSResultErrorDomain @"CKKSResultOperationError"
51 CKKSResultSubresultError
= 1,
52 CKKSResultSubresultCancelled
= 2,
53 CKKSResultTimedOut
= 3,
56 @interface CKKSResultOperation
: NSBlockOperation
57 @property NSError
* error
;
58 @property NSDate
* finishDate
;
59 @property CKKSCondition
* completionHandlerDidRunCondition
;
61 // Very similar to addDependency, but:
62 // if the dependent operation has an error or is canceled, cancel this operation
63 - (void)addSuccessDependency
: (CKKSResultOperation
*) operation
;
65 // Call to check if you should run.
66 // Note: all subclasses must call this if they'd like to comply with addSuccessDependency
67 // Also sets your .error property to encapsulate the upstream error
68 - (bool)allDependentsSuccessful
;
70 // Allows you to time out CKKSResultOperations: if they haven't started by now, they'll cancel themselves
71 // and set their error to indicate the timeout
72 - (instancetype
)timeout
:(dispatch_time_t
)timeout
;
74 // Convenience constructor.
75 +(instancetype
)operationWithBlock
:(void (^)(void))block
;
76 +(instancetype
)named
: (NSString
*)name withBlock
: (void(^)(void)) block
;
79 @interface CKKSGroupOperation
: CKKSResultOperation
{
84 @property NSOperationQueue
* operationQueue
;
88 // For subclasses: override this to execute at Group operation start time
91 - (void)runBeforeGroupFinished
: (NSOperation
*) suboperation
;
92 - (void)dependOnBeforeGroupFinished
: (NSOperation
*) suboperation
;
95 #endif // CKKSGroupOperation_h