0001    //
0002    //  PromiseType.swift
0003    //  Deferred
0004    //
0005    //  Created by Zachary Waldowski on 8/29/15.
0006    //  Copyright © 2014-2015 Big Nerd Ranch. Licensed under MIT.
0007    //
0008    
0009    /// A promise models writing the result of some asynchronous operation.
0010    ///
0011    /// Promises should generally only be determined, or "filled", once. This allows
0012    /// an implementing type to clear a queue of subscribers, for instance, and
0013    /// provides consistent sharing of the determined value.
0014    ///
0015    /// An implementing type should discourage race conditions around filling.
0016    /// However, certain use cases inherently race (such as cancellation), and any
0017    /// attempts to check for programmer error should be active by default.
0018    ///
0019    public protocol PromiseType
Deferred.swift:41
public struct Deferred<Value>: FutureType, PromiseType {
PromiseType.swift:39
public extension PromiseType {
{ 0020 /// A type that represents the result of some asynchronous operation. 0021 typealias Value
PromiseType.swift:36
    func fill(value: Value) -> Bool
PromiseType.swift:59
    func fill(value: Value, assertIfFilled: Bool, file: StaticString = __FILE__, line: UInt = __LINE__) {
0022 0023 /// Create the promise in a default, unfilled state 0024 init() 0025 0026 /// Check whether or not the receiver is filled. 0027 var isFilled: Bool { get } 0028 0029 /// Determines the deferred value with a given result. 0030 /// 0031 /// Filling a deferred value should usually be attempted only once. An 0032 /// implementing type may choose to enforce this. 0033 /// 0034 /// - parameter value: A resolved value for the instance. 0035 /// - returns: Whether the promise was fulfilled with `value`. 0036 func fill
PromiseType.swift:60
        if !fill(value) && assertIfFilled {
(value: Value) -> Bool 0037 } 0038 0039 public extension PromiseType { 0040 /// Determines the deferred value with a given result. 0041 /// 0042 /// Filling a deferred value should usually be attempted only once. An 0043 /// implementing type may choose to enforce this by default. If an 0044 /// implementing type requires multiple potential fillers to race, the 0045 /// precondition may be disabled. 0046 /// 0047 /// * In playgrounds and unoptimized builds (the default for a "Debug" 0048 /// configuration), program execution should be stopped at the caller in 0049 /// a debuggable state. 0050 /// 0051 /// * In -O builds (the default for a "Release" configuration), program 0052 /// execution should stop. 0053 /// 0054 /// * In -Ounchecked builds, the programming error should be assumed to not 0055 /// exist. 0056 /// 0057 /// - parameter value: A resolved value for the instance. 0058 /// - parameter assertIfFilled: If `false`, race checking is disabled. 0059 func fill(value: Value, assertIfFilled: Bool, file: StaticString = __FILE__, line: UInt = __LINE__) { 0060 if !fill(value) && assertIfFilled { 0061 assertionFailure("Cannot fill an already-filled \(self.dynamicType)", file: file, line: line) 0062 } 0063 } 0064 } 0065