Skip to content

Commit

Permalink
Merge pull request BoltsFramework#162 from BoltsFramework/nlutsenko.n…
Browse files Browse the repository at this point in the history
…ullability

Added nullability annotations to Bolts Tasks.
  • Loading branch information
nlutsenko committed Oct 29, 2015
2 parents 5da97aa + 3c884d8 commit a523b10
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 14 deletions.
4 changes: 4 additions & 0 deletions Bolts/Common/BFCancellationToken.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#import <Bolts/BFCancellationTokenRegistration.h>

NS_ASSUME_NONNULL_BEGIN

/*!
A block that will be called when a token is cancelled.
*/
Expand All @@ -36,3 +38,5 @@ typedef void(^BFCancellationBlock)();
- (BFCancellationTokenRegistration *)registerCancellationObserverWithBlock:(BFCancellationBlock)block;

@end

NS_ASSUME_NONNULL_END
4 changes: 4 additions & 0 deletions Bolts/Common/BFCancellationTokenRegistration.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

/*!
Represents the registration of a cancellation observer with a cancellation token.
Can be used to unregister the observer at a later time.
Expand All @@ -23,3 +25,5 @@
- (void)dispose;

@end

NS_ASSUME_NONNULL_END
4 changes: 4 additions & 0 deletions Bolts/Common/BFCancellationTokenSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@class BFCancellationToken;

/*!
Expand Down Expand Up @@ -54,3 +56,5 @@
- (void)dispose;

@end

NS_ASSUME_NONNULL_END
4 changes: 4 additions & 0 deletions Bolts/Common/BFExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

/*!
An object that can run a given block.
*/
Expand Down Expand Up @@ -56,3 +58,5 @@
- (void)execute:(void(^)())block;

@end

NS_ASSUME_NONNULL_END
28 changes: 16 additions & 12 deletions Bolts/Common/BFTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#import <Bolts/BFCancellationToken.h>
#import <Bolts/BFDefines.h>

NS_ASSUME_NONNULL_BEGIN

/*!
Error domain used if there was multiple errors on <BFTask taskForCompletionOfAllTasks:>.
*/
Expand All @@ -36,13 +38,13 @@ extern NSString *const BFTaskMultipleExceptionsException;
/*!
A block that can act as a continuation for a task.
*/
typedef id(^BFContinuationBlock)(BFTask BF_GENERIC(BFGenericType) *task);
typedef __nullable id(^BFContinuationBlock)(BFTask BF_GENERIC(BFGenericType) *task);

/*!
Creates a task that is already completed with the given result.
@param result The result for the task.
*/
+ (instancetype)taskWithResult:(BFGenericType)result;
+ (instancetype)taskWithResult:(nullable BFGenericType)result;

/*!
Creates a task that is already completed with the given error.
Expand All @@ -66,15 +68,15 @@ typedef id(^BFContinuationBlock)(BFTask BF_GENERIC(BFGenericType) *task);
all of the input tasks have completed.
@param tasks An `NSArray` of the tasks to use as an input.
*/
+ (instancetype)taskForCompletionOfAllTasks:(NSArray *)tasks;
+ (instancetype)taskForCompletionOfAllTasks:(nullable NSArray *)tasks;

/*!
Returns a task that will be completed once all of the input tasks have completed.
If all tasks complete successfully without being faulted or cancelled the result will be
an `NSArray` of all task results in the order they were provided.
@param tasks An `NSArray` of the tasks to use as an input.
*/
+ (instancetype)taskForCompletionOfAllTasksWithResults:(NSArray *)tasks;
+ (instancetype)taskForCompletionOfAllTasksWithResults:(nullable NSArray *)tasks;

/*!
Returns a task that will be completed a certain amount of time in the future.
Expand All @@ -90,7 +92,7 @@ typedef id(^BFContinuationBlock)(BFTask BF_GENERIC(BFGenericType) *task);
@param token The cancellation token (optional).
*/
+ (instancetype)taskWithDelay:(int)millis
cancellationToken:(BFCancellationToken *)token;
cancellationToken:(nullable BFCancellationToken *)token;

/*!
Returns a task that will be completed after the given block completes with
Expand All @@ -110,17 +112,17 @@ typedef id(^BFContinuationBlock)(BFTask BF_GENERIC(BFGenericType) *task);
/*!
The result of a successful task.
*/
@property (nonatomic, strong, readonly) BFGenericType result;
@property (nullable, nonatomic, strong, readonly) BFGenericType result;

/*!
The error of a failed task.
*/
@property (nonatomic, strong, readonly) NSError *error;
@property (nullable, nonatomic, strong, readonly) NSError *error;

/*!
The exception of a failed task.
*/
@property (nonatomic, strong, readonly) NSException *exception;
@property (nullable, nonatomic, strong, readonly) NSException *exception;

/*!
Whether this task has been cancelled.
Expand Down Expand Up @@ -163,7 +165,7 @@ typedef id(^BFContinuationBlock)(BFTask BF_GENERIC(BFGenericType) *task);
this method will not be completed until that task is completed.
*/
- (instancetype)continueWithBlock:(BFContinuationBlock)block
cancellationToken:(BFCancellationToken *)cancellationToken;
cancellationToken:(nullable BFCancellationToken *)cancellationToken;

/*!
Enqueues the given block to be run once this task is complete.
Expand All @@ -188,7 +190,7 @@ typedef id(^BFContinuationBlock)(BFTask BF_GENERIC(BFGenericType) *task);
*/
- (instancetype)continueWithExecutor:(BFExecutor *)executor
block:(BFContinuationBlock)block
cancellationToken:(BFCancellationToken *)cancellationToken;
cancellationToken:(nullable BFCancellationToken *)cancellationToken;

/*!
Identical to continueWithBlock:, except that the block is only run
Expand All @@ -214,7 +216,7 @@ typedef id(^BFContinuationBlock)(BFTask BF_GENERIC(BFGenericType) *task);
this method will not be completed until that task is completed.
*/
- (instancetype)continueWithSuccessBlock:(BFContinuationBlock)block
cancellationToken:(BFCancellationToken *)cancellationToken;
cancellationToken:(nullable BFCancellationToken *)cancellationToken;

/*!
Identical to continueWithExecutor:withBlock:, except that the block
Expand Down Expand Up @@ -246,7 +248,7 @@ typedef id(^BFContinuationBlock)(BFTask BF_GENERIC(BFGenericType) *task);
*/
- (instancetype)continueWithExecutor:(BFExecutor *)executor
successBlock:(BFContinuationBlock)block
cancellationToken:(BFCancellationToken *)cancellationToken;
cancellationToken:(nullable BFCancellationToken *)cancellationToken;

/*!
Waits until this operation is completed.
Expand All @@ -257,3 +259,5 @@ typedef id(^BFContinuationBlock)(BFTask BF_GENERIC(BFGenericType) *task);
- (void)waitUntilFinished;

@end

NS_ASSUME_NONNULL_END
8 changes: 6 additions & 2 deletions Bolts/Common/BFTaskCompletionSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#import <Bolts/BFDefines.h>

NS_ASSUME_NONNULL_BEGIN

@class BFTask BF_GENERIC(BFGenericType);

/*!
Expand All @@ -36,7 +38,7 @@
Attempting to set this for a completed task will raise an exception.
@param result The result of the task.
*/
- (void)setResult:(BFGenericType)result;
- (void)setResult:(nullable BFGenericType)result;

/*!
Completes the task by setting the error.
Expand All @@ -62,7 +64,7 @@
Sets the result of the task if it wasn't already completed.
@returns whether the new value was set.
*/
- (BOOL)trySetResult:(BFGenericType)result;
- (BOOL)trySetResult:(nullable BFGenericType)result;

/*!
Sets the error of the task if it wasn't already completed.
Expand All @@ -85,3 +87,5 @@
- (BOOL)trySetCancelled;

@end

NS_ASSUME_NONNULL_END
4 changes: 4 additions & 0 deletions Bolts/Common/Bolts.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#import <Bolts/BFWebViewAppLinkResolver.h>
#endif

NS_ASSUME_NONNULL_BEGIN

/*! @abstract 80175001: There were multiple errors. */
extern NSInteger const kBFMultipleErrorsError;

Expand All @@ -41,3 +43,5 @@ extern NSInteger const kBFMultipleErrorsError;
+ (NSString *)version;

@end

NS_ASSUME_NONNULL_END

0 comments on commit a523b10

Please sign in to comment.