Inherits from NSObject
Declared in BFTask.h

Overview

The consumer view of a Task. A BFTask has methods to inspect the state of the task, and to add continuations to be run once the task is complete.

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

BFTask.h

completed

Whether this task has completed.

@property (nonatomic, assign, readonly, getter=isCompleted) BOOL completed

Discussion

Whether this task has completed.

Declared In

BFTask.h

error

The error of a failed task.

@property (nonatomic, strong, readonly) NSError *error

Discussion

The error of a failed task.

Declared In

BFTask.h

exception

The exception of a failed task.

@property (nonatomic, strong, readonly) NSException *exception

Discussion

The exception of a failed task.

Declared In

BFTask.h

result

The result of a successful task.

@property (nonatomic, strong, readonly) id result

Discussion

The result of a successful task.

Declared In

BFTask.h

Class Methods

cancelledTask

Creates a task that is already cancelled.

+ (instancetype)cancelledTask

Discussion

Creates a task that is already cancelled.

Declared In

BFTask.h

taskForCompletionOfAllTasks:

Returns a task that will be completed (with result == nil) once all of the input tasks have completed.

+ (instancetype)taskForCompletionOfAllTasks:(id)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

BFTask.h

taskFromExecutor:withBlock:

Returns a task that will be completed after the given block completes with the specified executor.

+ (instancetype)taskFromExecutor:(id)executor withBlock:(id)block

Parameters

executor

A BFExecutor 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 BFTask, 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

BFTask.h

taskWithDelay:

Returns a task that will be completed a certain amount of time in the future.

+ (instancetype)taskWithDelay:(id)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

BFTask.h

taskWithError:

Creates a task that is already completed with the given error.

+ (instancetype)taskWithError:(id)error

Parameters

error

The error for the task.

Discussion

Creates a task that is already completed with the given error.

Declared In

BFTask.h

taskWithException:

Creates a task that is already completed with the given exception.

+ (instancetype)taskWithException:(id)exception

Parameters

exception

The exception for the task.

Discussion

Creates a task that is already completed with the given exception.

Declared In

BFTask.h

taskWithResult:

Creates a task that is already completed with the given result.

+ (instancetype)taskWithResult:(id)result

Parameters

result

The result for the task.

Discussion

Creates a task that is already completed with the given result.

Declared In

BFTask.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:(id)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 BFTask, 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

BFTask.h

continueWithExecutor:withBlock:

Enqueues the given block to be run once this task is complete.

- (instancetype)continueWithExecutor:(id)executor withBlock:(id)block

Parameters

executor

A BFExecutor 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 BFTask, 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

BFTask.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:(id)executor withSuccessBlock:(id)block

Parameters

executor

A BFExecutor 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 BFTask, 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

BFTask.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:(id)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 BFTask, 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

BFTask.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

BFTask.h