FutureBatchOf

Undocumented

  • completionsFuture returns an array of individual Completion values - returns: a Future<[Completion<T>]> always returns with a Success. Returns an array of the individual Future.Completion values for each subFuture.

    Declaration

    Swift

    public internal(set) var resultsFuture : Future<[FutureResult<T>]>
  • batchFuture succeeds iff all subFutures succeed. The result is an array [T]. it does not complete until all futures have been completed within the batch (even if some fail or are cancelled).

    Declaration

    Swift

    public internal(set) lazy var batchFuture : Future<[T]> = FutureBatchOf.futureFromResultsFuture(self.resultsFuture)
  • future succeeds iff all subfutures succeed. Will complete with a Fail or Cancel as soon as the first sub future is failed or cancelled. future may complete, while some subfutures are still running, if one completes with a Fail or Canycel.

    If it’s important to know that all Futures have completed, you can alertnatively use batchFuture and cancelRemainingFuturesOnFirstFail() or cancelRemainingFuturesOnFirstFailOrCancel(). batchFuture will always wait for all subFutures to complete before finishing, but will wait for the cancellations to be processed before exiting. this wi

    Declaration

    Swift

    public internal(set) lazy var future : Future<[T]> = self._onFirstFailOrCancel()
  • takes a type-safe list of Futures.

    Declaration

    Swift

    public init(f : [Future<T>])
  • takes a list of Futures. Each future will be converted into a Future that returns T.

    Declaration

    Swift

    public convenience init(_ futures : [FutureProtocol])
  • Allows you to define a Block that will execute as soon as each Future completes. The biggest difference between using onEachComplete() or just using the future var, is that this block will execute as soon as each future completes. The block will be executed repeately, until all sub futures have been completed.

    This can also be used to compose a new Future[Type]. All the values returned from the block will be assembled and returned in a new Future<[Type]. If needed.

    Declaration

    Swift

    public final func onEachComplete<__Type>(executor : Executor = .Primary,
            block:(value:FutureResult<T>, future:Future<T>, index:Int)-> __Type) -> Future<[__Type]>

    Parameters

    executor

    executor to use to run the block :block: block block to execute as soon as each Future completes.

  • Undocumented

  • takes an array of futures returns a new array of futures converted to the desired Type <__Type> Any is the only type that is guaranteed to always work. Useful if you have a bunch of mixed type Futures, and convert them into a list of Future types.

    WARNING: if T as! __Type isn’t legal, than your code may generate an exception.

    works iff the following code works:

    let t : T let s = t as! __Type

    example:

    Declaration

    Swift

    public class func convertArray<__Type>(array:[Future<T>]) -> [Future<__Type>]

    Parameters

    array

    array of Futures

    Return Value

    an array of Futures converted to return type

  • takes an array of futures returns a new array of futures converted to the desired Type ‘Any’ is the only type that is guaranteed to always work. Useful if you have a bunch of mixed type Futures, and convert them into a list of Future types.

    Declaration

    Swift

    public class func convertArray<__Type>(array:[FutureProtocol]) -> [Future<__Type>]

    Parameters

    array

    array of Futures

    Return Value

    an array of Futures converted to return type

  • takes an array of futures of type [Future<T>] and returns a single future of type Future<[Completion] So you can now just add a single onSuccess/onFail/onCancel handler that will be executed once all of the sub-futures in the array have completed. This future always returns .Success, with a result individual completions. This future will never complete, if one of it’s sub futures doesn’t complete. you have to check the result of the array individually if you care about the specific outcome of a subfuture

    Declaration

    Swift

    public class func resultsFuture(array : [Future<T>]) -> Future<[FutureResult<T>]>

    Parameters

    array

    an array of Futures of type [T].

    Return Value

    a single future that returns an array of Completion<T> values.

  • takes a future of type Future<[Completion<T>] (usually returned from completionFutures()) and returns a single future of type Future<[T]>. It checks all the completion values and will return .Fail if one of the Futures Failed. will return .Cancelled if there were no .Fail completions, but at least one subfuture was cancelled. returns .Success iff all the subfutures completed.

    Declaration

    Swift

    public class func futureFromResultsFuture<T>(f : Future<[FutureResult<T>]>) -> Future<[T]>

    Parameters

    a

    completions future of type Future<[Completion<T>]>

    Return Value

    a single future that returns an array an array of [T].

  • takes an array of futures of type [Future<T>] and returns a single future of type Future<[T]> So you can now just add a single onSuccess/onFail/onCancel handler that will be executed once all of the sub-futures in the array have completed. It checks all the completion values and will return .Fail if one of the Futures Failed. will return .Cancelled if there were no .Fail completions, but at least one subfuture was cancelled. returns .Success iff all the subfutures completed.

    this Future will not complete until ALL subfutures have finished. If you need a Future that completes as soon as single Fail or Cancel is seen, use a FutureBatch object and use the var future or the method onFirstFail()

    Declaration

    Swift

    public final class func futureFromArrayOfFutures(array : [Future<T>]) -> Future<[T]>

    Parameters

    array

    an array of Futures of type [T].

    Return Value

    a single future that returns an array of [T], or a .Fail or .Cancel if a single sub-future fails or is canceled.