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@
24 #ifndef CKKSResultOperation_h
25 #define CKKSResultOperation_h
27 #import <Foundation/Foundation.h>
28 #import <dispatch/dispatch.h>
29 #import "keychain/ckks/NSOperationCategories.h"
33 #define CKKSResultErrorDomain @"CKKSResultOperationError"
35 CKKSResultSubresultError
= 1,
36 CKKSResultSubresultCancelled
= 2,
37 CKKSResultTimedOut
= 3,
40 @interface CKKSResultOperation
: NSBlockOperation
41 @property NSError
* error
;
42 @property NSDate
* finishDate
;
43 @property CKKSCondition
* completionHandlerDidRunCondition
;
45 // Very similar to addDependency, but:
46 // if the dependent operation has an error or is canceled, cancel this operation
47 - (void)addSuccessDependency
: (CKKSResultOperation
*) operation
;
48 - (void)addNullableSuccessDependency
:(CKKSResultOperation
*)operation
;
50 // Call to check if you should run.
51 // Note: all subclasses must call this if they'd like to comply with addSuccessDependency
52 // Also sets your .error property to encapsulate the upstream error
53 - (bool)allDependentsSuccessful
;
55 // Allows you to time out CKKSResultOperations: if they haven't started by now, they'll cancel themselves
56 // and set their error to indicate the timeout
57 - (instancetype
)timeout
:(dispatch_time_t
)timeout
;
59 // Convenience constructor.
60 +(instancetype
)operationWithBlock
:(void (^)(void))block
;
61 +(instancetype
)named
: (NSString
*)name withBlock
: (void(^)(void)) block
;
63 // Determine if all these operations were successful, and set this operation's result if not.
64 - (bool)allSuccessful
: (NSArray
<CKKSResultOperation
*>*) operations
;
66 // Call this to prevent the timeout on this operation from occuring.
67 // Upon return, either this operation is cancelled, or the timeout will never fire.
68 -(void)invalidateTimeout
;
71 #endif // CKKSResultOperation_h