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
DelayedPromisethat can be resolved with the given block.The
DelayedPromisewon’t execute the block until the.promiseproperty is accessed.Declaration
Swift
public init(on context: PromiseContext, _ handler: @escaping (_ resolver: Resolver) -> Void)Parameters
contextThe context to execute the handler on.
handlerA block that may be executed in order to fulfill the promise.
resolverThe
Resolverused to resolve the promise. -
Returns a
Promisethat asynchronously contains the value of the computation.If the computation has not yet started, this is equivalent to creating a
Promisewith the samePromiseContextand handler. If the computation has started, this returns the samePromiseas the first time it was accessed.Declaration
Swift
public var promise: Promise<Value, Error> { get } -
Two
DelayedPromises compare as equal if they would produce equalPromises.Declaration
Swift
public static func == (lhs: DelayedPromise, rhs: DelayedPromise) -> Bool
View on GitHub
DelayedPromise Structure Reference