Future

public class Future<S> : Completing

Future is a proxy of value that will be available at some point in the future.

  • Flattens two nested futures

    Declaration

    Swift

    func flatten() -> Future<S.Success>

    Return Value

    flattened future

  • Flattens channel nested in future

    Declaration

    Swift

    func flatten() -> Channel<S.Update, S.Success>

    Return Value

    flattened future

  • Makes completed future

    Declaration

    Swift

    static func completed(_ completion: Fallible<Success>) -> Future<Success>
  • Makes succeeded future

    Declaration

    Swift

    static func succeeded(_ success: Success) -> Future<Success>
  • Makes succeeded future

    Declaration

    Swift

    static func just(_ success: Success) -> Future<Success>
  • Makes failed future

    Declaration

    Swift

    static func failed(_ failure: Swift.Error) -> Future<Success>
  • Makes cancelled (failed with AsyncNinjaError.cancelled) future

    Declaration

    Swift

    static var cancelled: Future<Success> { get }
  • Transforms the future to a future of unrelated type Correctness of such transformation is left on our behalf

    Declaration

    Swift

    func staticCast<T>() -> Future<T>
  • Transforms the future to a channel

    Declaration

    Swift

    func makeChannel<Update>(updates: [Update] = []) -> Channel<Update, Success>
  • Transforms the future to a channel of unrelated type Correctness of such transformation is left on our behalf

    Declaration

    Swift

    func staticCast<Update, T>(updates: [Update] = []) -> Channel<Update, T>
  • A textual representation of this instance.

    Declaration

    Swift

    public var description: String { get }
  • A textual representation of this instance, suitable for debugging.

    Declaration

    Swift

    public var debugDescription: String { get }
  • Applies the transformation to the future

    Declaration

    Swift

    func map<T>(
      executor: Executor = .primary,
      pure: Bool = true,
      _ transform: @escaping (_ success: Success) throws -> T
      ) -> Future<T>

    Parameters

    executor

    is Executor to execute transform on

    transform

    is block to execute on successful completion of original future. Return from transformation block will cause returned future to complete successfuly. Throw from transformation block will returned future to complete with failure

    success

    is a success value of original future

    Return Value

    transformed future

  • Applies the transformation to the future and flattens future returned by transformation

    Declaration

    Swift

    func flatMap<T: Completing>(
      executor: Executor = .primary,
      pure: Bool = true,
      transform: @escaping (_ success: Success) throws -> T
      ) -> Future<T.Success>

    Parameters

    executor

    is Executor to execute transform on

    transform

    is block to execute on successful completion of original future. Return from transformation block will cause returned future to complete with future. Throw from transformation block will returned future to complete with failure

    success

    is a success value of original future

    Return Value

    transformed future

  • Applies the transformation to the future and flattens channel returned by transformation

    Declaration

    Swift

    func flatMap<T: Completing&Updating>(
      executor: Executor = .primary,
      pure: Bool = true,
      transform: @escaping (_ success: Success) throws -> T
      ) -> Channel<T.Update, T.Success>

    Parameters

    executor

    is Executor to execute transform on

    transform

    is block to execute on successful completion of original future. Return from transformation block will cause returned channel to complete with future. Throw from transformation block will returned future to complete with failure

    success

    is a success value of original future

    Return Value

    transformed future

  • Applies the transformation to the future

    Declaration

    Swift

    func map<T, C: ExecutionContext>(
      context: C,
      executor: Executor? = nil,
      pure: Bool = true,
      _ transform: @escaping (_ strongContext: C, _ Success: Success) throws -> T
      ) -> Future<T>

    Parameters

    context

    is ExecutionContext to perform transform on. Instance of context will be passed as the first argument to the transformation. Transformation will not be executed if executor was deallocated before execution, returned future will fail with AsyncNinjaError.contextDeallocated error

    executor

    is Executor to override executor provided by context

    transform

    is block to execute on successful completion of original future. Return from transformation block will cause returned future to complete successfuly. Throw from transformation block will returned future to complete with failure

    strongContext

    is ExecutionContext restored from weak reference of context passed to method

    Success

    is a success value of original future

    Return Value

    transformed future

  • Applies the transformation to the future and flattens future returned by transformation

    Declaration

    Swift

    func flatMap<T: Completing, C: ExecutionContext>(
      context: C,
      executor: Executor? = nil,
      pure: Bool = true,
      transform: @escaping (_ strongContext: C, _ Success: Success) throws -> T
      ) -> Future<T.Success>

    Parameters

    context

    is ExecutionContext to perform transform on. Instance of context will be passed as the first argument to the transformation. Transformation will not be executed if executor was deallocated before execution, returned future will fail with AsyncNinjaError.contextDeallocated error

    executor

    is Executor to override executor provided by context

    transform

    is block to execute on successful completion of original future. Return from transformation block will cause returned future to complete with future. Throw from transformation block will returned future to complete with failure

    strongContext

    is ExecutionContext restored from weak reference of context passed to method

    Success

    is a success value of original future

    Return Value

    transformed future

  • Applies the transformation to the future and flattens channel returned by transformation

    Declaration

    Swift

    func flatMap<T: Completing&Updating, C: ExecutionContext>(
      context: C,
      executor: Executor? = nil,
      pure: Bool = true,
      transform: @escaping (_ strongContext: C, _ Success: Success) throws -> T
      ) -> Channel<T.Update, T.Success>

    Parameters

    context

    is ExecutionContext to perform transform on. Instance of context will be passed as the first argument to the transformation. Transformation will not be executed if executor was deallocated before execution, returned future will fail with AsyncNinjaError.contextDeallocated error

    executor

    is Executor to override executor provided by context

    transform

    is block to execute on successful completion of original channel. Return from transformation block will cause returned channel to complete with channel. Throw from transformation block will returned channel to complete with failure

    strongContext

    is ExecutionContext restored from weak reference of context passed to method

    Success

    is a success value of original future

    Return Value

    transformed future

  • Makes future with delayed completion

    Declaration

    Swift

    func delayed(timeout: Double) -> Future<Success>

    Parameters

    timeout

    is Double (seconds) to delay competion of original future with.

    Return Value

    delayed future