PromiseProtocol
public protocol PromiseProtocol
A promise models writing the result of some asynchronous operation.
Promises should generally only be determined, or filled
, once. This allows
an implementing type to clear a queue of subscribers, for instance, and
provides consistent sharing of the determined value.
An implementing type should discourage race conditions around filling. However, certain use cases inherently race (such as cancellation). Any attempts to check for programmer error should be active by default.
-
A type that represents the result of some asynchronous operation.
Declaration
Swift
associatedtype Value
-
Creates an instance in a default, unfilled state.
Declaration
Swift
init()
-
isFilled
Default implementationCheck whether or not the receiver is filled.
Default Implementation
By default, checks for a fulfilled future value.
Declaration
Swift
var isFilled: Bool { get }
-
Determines the promise with
value
.Filling a deferred value should usually be attempted only once.
Declaration
Swift
@discardableResult func fill(with value: Value) -> Bool
Return Value
Whether the promise was fulfilled with
value
.
-
mustFill(with:file:line:)
Extension methodDetermines the deferred
value
.Filling a deferred value should usually be attempted only once. A user may choose to enforce this.
In playgrounds and unoptimized builds (the default for a
Debug
configuration) where the deferred value is already filled, program execution will be stopped in a debuggable state.In optimized builds (the default for a
Release
configuration) where the deferred value is already filled, stop program execution.In unchecked builds, filling a deferred value that is already filled is a serious programming error. The optimizer may assume that it is not possible.
Declaration
Swift
@inlinable public func mustFill(with value: Value, file: StaticString = #file, line: UInt = #line)