OSSTask Class Reference
Declared in | OSSTask.h OSSTask.m |
Overview
The consumer view of a Task. A OSSTask has methods to inspect the state of the task, and to add continuations to be run once the task is complete.
Tasks
-
+ taskWithResult:
-
+ taskWithError:
-
+ taskWithException:
-
+ cancelledTask
-
+ taskForCompletionOfAllTasks:
-
+ taskForCompletionOfAllTasksWithResults:
-
+ taskWithDelay:
-
+ taskWithDelay:cancellationToken:
-
+ taskFromExecutor:withBlock:
-
result
property -
error
property -
exception
property -
cancelled
property -
faulted
property -
completed
property -
– continueWithBlock:
-
– continueWithBlock:cancellationToken:
-
– continueWithExecutor:withBlock:
-
– continueWithExecutor:block:cancellationToken:
-
– continueWithSuccessBlock:
-
– continueWithSuccessBlock:cancellationToken:
-
– continueWithExecutor:withSuccessBlock:
-
– continueWithExecutor:successBlock:cancellationToken:
-
– waitUntilFinished
Properties
cancelled
Whether this task has been cancelled.
@property (nonatomic, assign, readonly, getter=isCancelled) BOOL cancelled
Discussion
Whether this task has been cancelled.
Declared In
OSSTask.h
completed
Whether this task has completed.
@property (nonatomic, assign, readonly, getter=isCompleted) BOOL completed
Discussion
Whether this task has completed.
Declared In
OSSTask.h
error
The error of a failed task.
@property (nonatomic, strong, readonly) NSError *error
Discussion
The error of a failed task.
Declared In
OSSTask.h
exception
The exception of a failed task.
@property (nonatomic, strong, readonly) NSException *exception
Discussion
The exception of a failed task.
Declared In
OSSTask.h
Class Methods
cancelledTask
Creates a task that is already cancelled.
+ (instancetype)cancelledTask
Discussion
Creates a task that is already cancelled.
Declared In
OSSTask.h
taskForCompletionOfAllTasks:
Returns a task that will be completed (with result == nil) once all of the input tasks have completed.
+ (instancetype)taskForCompletionOfAllTasks:(NSArray *)tasks
Parameters
- tasks
An
NSArray
of the tasks to use as an input.
Discussion
Returns a task that will be completed (with result == nil) once all of the input tasks have completed.
Declared In
OSSTask.h
taskForCompletionOfAllTasksWithResults:
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.
+ (instancetype)taskForCompletionOfAllTasksWithResults:(NSArray *)tasks
Parameters
- tasks
An
NSArray
of the tasks to use as an input.
Discussion
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.
Declared In
OSSTask.h
taskFromExecutor:withBlock:
+ (instancetype)taskFromExecutor:(OSSExecutor *)executor withBlock:(id ( ^ ) ( ))block
Parameters
- executor
A OSSExecutor responsible for determining how the continuation block will be run.
- block
The block to immediately schedule to run with the given executor.
Return Value
A task that will be completed after block has run. If block returns a OSSTask, then the task returned from this method will not be completed until that task is completed.
Discussion
Returns a task that will be completed after the given block completes with the specified executor.
Declared In
OSSTask.h
taskWithDelay:
Returns a task that will be completed a certain amount of time in the future.
+ (instancetype)taskWithDelay:(int)millis
Parameters
- millis
The approximate number of milliseconds to wait before the task will be finished (with result == nil).
Discussion
Returns a task that will be completed a certain amount of time in the future.
Declared In
OSSTask.h
taskWithDelay:cancellationToken:
Returns a task that will be completed a certain amount of time in the future.
+ (instancetype)taskWithDelay:(int)millis cancellationToken:(OSSCancellationToken *)token
Parameters
- millis
The approximate number of milliseconds to wait before the task will be finished (with result == nil).
- token
The cancellation token (optional).
Discussion
Returns a task that will be completed a certain amount of time in the future.
Declared In
OSSTask.h
taskWithError:
+ (instancetype)taskWithError:(NSError *)error
Parameters
- error
The error for the task.
Declared In
OSSTask.h
taskWithException:
+ (instancetype)taskWithException:(NSException *)exception
Parameters
- exception
The exception for the task.
Declared In
OSSTask.h
Instance Methods
continueWithBlock:
Enqueues the given block to be run once this task is complete. This method uses a default execution strategy. The block will be run on the thread where the previous task completes, unless the the stack depth is too deep, in which case it will be run on a dispatch queue with default priority.
- (instancetype)continueWithBlock:(OSSContinuationBlock)block
Parameters
- block
The block to be run once this task is complete.
Return Value
A task that will be completed after block has run. If block returns a OSSTask, then the task returned from this method will not be completed until that task is completed.
Discussion
Enqueues the given block to be run once this task is complete. This method uses a default execution strategy. The block will be run on the thread where the previous task completes, unless the the stack depth is too deep, in which case it will be run on a dispatch queue with default priority.
Declared In
OSSTask.h
continueWithBlock:cancellationToken:
Enqueues the given block to be run once this task is complete. This method uses a default execution strategy. The block will be run on the thread where the previous task completes, unless the the stack depth is too deep, in which case it will be run on a dispatch queue with default priority.
- (instancetype)continueWithBlock:(OSSContinuationBlock)block cancellationToken:(OSSCancellationToken *)cancellationToken
Parameters
- block
The block to be run once this task is complete.
- cancellationToken
The cancellation token (optional).
Return Value
A task that will be completed after block has run. If block returns a OSSTask, then the task returned from this method will not be completed until that task is completed.
Discussion
Enqueues the given block to be run once this task is complete. This method uses a default execution strategy. The block will be run on the thread where the previous task completes, unless the the stack depth is too deep, in which case it will be run on a dispatch queue with default priority.
Declared In
OSSTask.h
continueWithExecutor:block:cancellationToken:
Enqueues the given block to be run once this task is complete.
- (instancetype)continueWithExecutor:(OSSExecutor *)executor block:(OSSContinuationBlock)block cancellationToken:(OSSCancellationToken *)cancellationToken
Parameters
- executor
A OSSExecutor responsible for determining how the continuation block will be run.
- block
The block to be run once this task is complete.
- cancellationToken
The cancellation token (optional).
Return Value
A task that will be completed after block has run. If block returns a OSSTask, then the task returned from his method will not be completed until that task is completed.
Discussion
Enqueues the given block to be run once this task is complete.
Declared In
OSSTask.h
continueWithExecutor:successBlock:cancellationToken:
Identical to continueWithExecutor:withBlock:, except that the block is only run if this task did not produce a cancellation, error, or exception. If it did, then the failure will be propagated to the returned task.
- (instancetype)continueWithExecutor:(OSSExecutor *)executor successBlock:(OSSContinuationBlock)block cancellationToken:(OSSCancellationToken *)cancellationToken
Parameters
- executor
A OSSExecutor responsible for determining how the continuation block will be run.
- block
The block to be run once this task is complete.
- cancellationToken
The cancellation token (optional).
Return Value
A task that will be completed after block has run. If block returns a OSSTask, then the task returned from this method will not be completed until that task is completed.
Discussion
Identical to continueWithExecutor:withBlock:, except that the block is only run if this task did not produce a cancellation, error, or exception. If it did, then the failure will be propagated to the returned task.
Declared In
OSSTask.h
continueWithExecutor:withBlock:
Enqueues the given block to be run once this task is complete.
- (instancetype)continueWithExecutor:(OSSExecutor *)executor withBlock:(OSSContinuationBlock)block
Parameters
- executor
A OSSExecutor responsible for determining how the continuation block will be run.
- block
The block to be run once this task is complete.
Return Value
A task that will be completed after block has run. If block returns a OSSTask, then the task returned from this method will not be completed until that task is completed.
Discussion
Enqueues the given block to be run once this task is complete.
Declared In
OSSTask.h
continueWithExecutor:withSuccessBlock:
Identical to continueWithExecutor:withBlock:, except that the block is only run if this task did not produce a cancellation, error, or exception. If it did, then the failure will be propagated to the returned task.
- (instancetype)continueWithExecutor:(OSSExecutor *)executor withSuccessBlock:(OSSContinuationBlock)block
Parameters
- executor
A OSSExecutor responsible for determining how the continuation block will be run.
- block
The block to be run once this task is complete.
Return Value
A task that will be completed after block has run. If block returns a OSSTask, then the task returned from this method will not be completed until that task is completed.
Discussion
Identical to continueWithExecutor:withBlock:, except that the block is only run if this task did not produce a cancellation, error, or exception. If it did, then the failure will be propagated to the returned task.
Declared In
OSSTask.h
continueWithSuccessBlock:
Identical to continueWithBlock:, except that the block is only run if this task did not produce a cancellation, error, or exception. If it did, then the failure will be propagated to the returned task.
- (instancetype)continueWithSuccessBlock:(OSSContinuationBlock)block
Parameters
- block
The block to be run once this task is complete.
Return Value
A task that will be completed after block has run. If block returns a OSSTask, then the task returned from this method will not be completed until that task is completed.
Discussion
Identical to continueWithBlock:, except that the block is only run if this task did not produce a cancellation, error, or exception. If it did, then the failure will be propagated to the returned task.
Declared In
OSSTask.h
continueWithSuccessBlock:cancellationToken:
Identical to continueWithBlock:, except that the block is only run if this task did not produce a cancellation, error, or exception. If it did, then the failure will be propagated to the returned task.
- (instancetype)continueWithSuccessBlock:(OSSContinuationBlock)block cancellationToken:(OSSCancellationToken *)cancellationToken
Parameters
- block
The block to be run once this task is complete.
- cancellationToken
The cancellation token (optional).
Return Value
A task that will be completed after block has run. If block returns a OSSTask, then the task returned from this method will not be completed until that task is completed.
Discussion
Identical to continueWithBlock:, except that the block is only run if this task did not produce a cancellation, error, or exception. If it did, then the failure will be propagated to the returned task.
Declared In
OSSTask.h
waitUntilFinished
Waits until this operation is completed. This method is inefficient and consumes a thread resource while it’s running. It should be avoided. This method logs a warning message if it is used on the main thread.
- (void)waitUntilFinished
Discussion
Waits until this operation is completed. This method is inefficient and consumes a thread resource while it’s running. It should be avoided. This method logs a warning message if it is used on the main thread.
Declared In
OSSTask.h