Skip to content
This repository was archived by the owner on Aug 29, 2022. It is now read-only.

Commit 7178356

Browse files
committed
Finally move isFilled and value out of Future into unit tests
1 parent d364831 commit 7178356

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

Sources/Deferred/Future.swift

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,6 @@ public protocol FutureProtocol: CustomDebugStringConvertible, CustomReflectable
5757
func wait(until time: DispatchTime) -> Value?
5858
}
5959

60-
extension FutureProtocol {
61-
/// Waits for the value to become determined, then returns it.
62-
///
63-
/// This is equivalent to unwrapping the value of calling `wait(.Forever)`,
64-
/// but may be more efficient.
65-
///
66-
/// This getter will unnecessarily block execution. It might be useful for
67-
/// testing, but otherwise it should be strictly avoided.
68-
///
69-
/// - returns: The determined value.
70-
var value: Value {
71-
return wait(until: .distantFuture).unsafelyUnwrapped
72-
}
73-
74-
/// Check whether or not the receiver is filled.
75-
var isFilled: Bool {
76-
return wait(until: .now()) != nil
77-
}
78-
}
79-
8060
// MARK: - Default implementations
8161

8262
extension FutureProtocol {
@@ -85,11 +65,12 @@ extension FutureProtocol {
8565
var ret = ""
8666
ret.append(contentsOf: "\(Self.self)".prefix(while: { $0 != "<" }))
8767
ret.append("(")
88-
if Value.self == Void.self, isFilled {
68+
switch peek() {
69+
case _? where Value.self == Void.self:
8970
ret.append("filled")
90-
} else if let value = peek() {
71+
case let value?:
9172
debugPrint(value, terminator: "", to: &ret)
92-
} else {
73+
case nil:
9374
ret.append("not filled")
9475
}
9576
ret.append(")")

Sources/Deferred/FutureCollections.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ private struct AllFilledFuture<Value>: FutureProtocol {
3737
}
3838

3939
group.notify(queue: queue) { [combined] in
40-
combined.fill(with: array.map { $0.value })
40+
// Expect each to be filled right now.
41+
// swiftlint:disable:next force_unwrapping
42+
combined.fill(with: array.map({ $0.peek()! }))
4143
}
4244
}
4345

Tests/AllTestsCommon.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ extension XCTestCase {
4747
}
4848

4949
extension FutureProtocol {
50+
/// Waits for the value to become determined, then returns it.
51+
///
52+
/// This is equivalent to unwrapping the value of calling
53+
/// `wait(until: .distantFuture)`, but may be more efficient.
54+
///
55+
/// This getter will unnecessarily block execution. It might be useful for
56+
/// testing, but otherwise it should be strictly avoided.
57+
///
58+
/// - returns: The determined value.
59+
var value: Value {
60+
return wait(until: .distantFuture).unsafelyUnwrapped
61+
}
62+
63+
/// Check whether or not the receiver is filled.
64+
var isFilled: Bool {
65+
return peek() != nil
66+
}
67+
5068
func shortWait() -> Value? {
5169
return wait(until: .now() + 0.05)
5270
}

0 commit comments

Comments
 (0)