DelayedPromise

public struct DelayedPromise<Value, Error> : Equatable

DelayedPromise is like a Promise but it doesn’t invoke its callback until the .promise variable is accessed.

The purpose of DelayedPromise is to allow functions to return calculations that aren’t performed if they’re not needed.

Example:

func getUserInfo() -> (name: String, avatar: DelayedPromise<UIImage,Error>) {
    
}

let (name, avatar) = getUserInfo()
nameLabel.text = name
avatar.promise.then { [weak self] (image) in
    self?.imageView.image = image
}
  • The type of the promise resolver. See Promise<Value,Error>.Resolver.

    Declaration

    Swift

    public typealias Resolver = Promise<Value, Error>.Resolver
  • Returns a new DelayedPromise that can be resolved with the given block.

    The DelayedPromise won’t execute the block until the .promise property is accessed.

    Declaration

    Swift

    public init(on context: PromiseContext, _ handler: @escaping (_ resolver: Resolver) -> Void)

    Parameters

    context

    The context to execute the handler on.

    handler

    A block that may be executed in order to fulfill the promise.

    resolver

    The Resolver used to resolve the promise.

  • Returns a Promise that asynchronously contains the value of the computation.

    If the computation has not yet started, this is equivalent to creating a Promise with the same PromiseContext and handler. If the computation has started, this returns the same Promise as the first time it was accessed.

    Declaration

    Swift

    public var promise: Promise<Value, Error> { get }
  • Two DelayedPromises compare as equal if they would produce equal Promises.

    Declaration

    Swift

    public static func == (lhs: DelayedPromise, rhs: DelayedPromise) -> Bool