Promise
public final class Promise<T> : Thenable, CatchMixin
extension Promise: CustomStringConvertible
extension Promise: CustomDebugStringConvertible
A Promise
is a functional abstraction around a failable asynchronous operation.
See
Thenable
-
Initialize a new fulfilled promise.
We do not provide
init(value:)
because Swift is “greedy” and would pick that initializer in cases where it should pick one of the other more specific options leading to Promises withT
that is eg:Error
or worse(T->Void,Error->Void)
for uses of our PMK < 4 pending initializer due to Swift trailing closure syntax (nothing good comes without pain!).Though often easy to detect, sometimes these issues would be hidden by other type inference leading to some nasty bugs in production.
In PMK5 we tried to work around this by making the pending initializer take the form
Promise(.pending)
but this led to bad migration errors for PMK4 users. Hence instead we quickly released PMK6 and now only provide this initializer for making sealed & fulfilled promises.Usage is still (usually) good:
guard foo else { return .value(bar) }
Declaration
Swift
public static func value(_ value: T) -> Promise<T>
-
Initialize a new rejected promise.
Declaration
Swift
public init(error: Error)
-
See
Thenable.pipe
Declaration
Swift
public func pipe(to: @escaping (Result<T>) -> Void)
-
See
Thenable.result
Declaration
Swift
public var result: Result<T>? { get }
-
Undocumented
Declaration
Swift
func future() -> Future<T, Error>
-
Declaration
Swift
public var description: String { get }
Return Value
A description of the state of this promise.
-
Declaration
Swift
public var debugDescription: String { get }
Return Value
A debug-friendly description of the state of this promise.
-
Undocumented
Declaration
Swift
func always(on q: DispatchQueue = .main, execute body: @escaping () -> Void) -> Promise
-
Blocks this thread, so—you know—don’t call this on a serial thread that any part of your chain may use. Like the main thread for example.
Declaration
Swift
func wait() throws -> T
-
Undocumented
Declaration
Swift
convenience init(_ anyPromise: AnyPromise)