Inherits from NSObject
Declared in SCAsyncOpRelationsBuilder.h

Overview

This class contains some methods to control the flow of asynchronous operations of SCAsyncOp type.
With its help the user can avoid the “callback hell” problem and reduce the depth of asycnhronous calls.

To control the flow of SCExtendedAsyncOp operations please consider the SCAsyncOpRelationsBuilder class.
Alternatively, you can convert the operation using the [SCAsyncOpRelationsBuilder operationFromExtendedOperation:] class.

Tasks

  • + operationFromExtendedOperation:

    Converts an extended operation to a simplified one by currying progress and cancel callbacks.

  • + sequence:

    Converts operations array to a single operation. The operations will be executed one after another.
    If any operation fails, next ones won’t be executed. The error will be returned in the callback.
    On success the callback receives the result of the last operation.

  • + stopOnFirstSuccessInSequence:

    Executes operations in array one after another until one of them succeeds.

  • + group:

    Converts operations array to a single operation. The operations will be executed in parallel.
    A callback will be called after all operations are finished.
    If any operation fails, next ones will be executed. However, an error of the failed operation will be returned in the callback.
    On success the callback receives an array of single operation results.

  • + stopOnFirstErrorInGroup:

    Converts operations array to a single operation. The operations will be executed in parallel.
    If any operation fails, others are cancelled immediately. The error will be returned in the callback.
    On success the callback receives an array of single operation results.

Class Methods

group:

Converts operations array to a single operation. The operations will be executed in parallel.
A callback will be called after all operations are finished.
If any operation fails, next ones will be executed. However, an error of the failed operation will be returned in the callback.
On success the callback receives an array of single operation results.

+ (SCAsyncOp)group:(NSArray *)operations

Parameters

operations
  • NSArray of SCAsyncOp objects

Return Value

a single SCAsyncOp as a combination

SCAsyncOpRelationsBuilder group: @[a, b, c, d, e]
{
// when “c” and “e” failed
// then a, b, d are still running
// and result == nil
// error is non determined. It may be either c.error or e.error
} );

Discussion

Converts operations array to a single operation. The operations will be executed in parallel.
A callback will be called after all operations are finished.
If any operation fails, next ones will be executed. However, an error of the failed operation will be returned in the callback.
On success the callback receives an array of single operation results.

Declared In

SCAsyncOpRelationsBuilder.h

operationFromExtendedOperation:

Converts an extended operation to a simplified one by currying progress and cancel callbacks.

+ (SCAsyncOp)operationFromExtendedOperation:(SCExtendedAsyncOp)extendedOperation

Parameters

extendedOperation
  • an operation with progress, cancel and completion callbacks.

Return Value

  • an operation with completion callback only.

Discussion

Converts an extended operation to a simplified one by currying progress and cancel callbacks.

Declared In

SCAsyncOpRelationsBuilder.h

sequence:

Converts operations array to a single operation. The operations will be executed one after another.
If any operation fails, next ones won’t be executed. The error will be returned in the callback.
On success the callback receives the result of the last operation.

+ (SCAsyncOp)sequence:(NSArray *)operations

Parameters

operations
  • NSArray of SCAsyncOp objects

Return Value

a single SCAsyncOp as a combination

Discussion

Converts operations array to a single operation. The operations will be executed one after another.
If any operation fails, next ones won’t be executed. The error will be returned in the callback.
On success the callback receives the result of the last operation.

Declared In

SCAsyncOpRelationsBuilder.h

stopOnFirstErrorInGroup:

Converts operations array to a single operation. The operations will be executed in parallel.
If any operation fails, others are cancelled immediately. The error will be returned in the callback.
On success the callback receives an array of single operation results.

+ (SCAsyncOp)stopOnFirstErrorInGroup:(NSArray *)operations

Parameters

operations
  • NSArray of SCAsyncOp objects

Return Value

a single SCAsyncOp as a combination

Discussion

Converts operations array to a single operation. The operations will be executed in parallel.
If any operation fails, others are cancelled immediately. The error will be returned in the callback.
On success the callback receives an array of single operation results.

Declared In

SCAsyncOpRelationsBuilder.h

stopOnFirstSuccessInSequence:

Executes operations in array one after another until one of them succeeds.

+ (SCAsyncOp)stopOnFirstSuccessInSequence:(NSArray *)operations

Parameters

operations
  • NSArray of SCAsyncOp objects

Return Value

a single SCAsyncOp as a combination

Discussion

Executes operations in array one after another until one of them succeeds.

Declared In

SCAsyncOpRelationsBuilder.h