Skip to content

Commit 50045d3

Browse files
committed
Rename FutureValue to FutureResult, add result property to Future
1 parent a73b16c commit 50045d3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+445
-379
lines changed

Futures.xcodeproj/project.pbxproj

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
/* Begin PBXBuildFile section */
1010
B757AE1520B8921E00850F92 /* Futures.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B757AE0B20B8921E00850F92 /* Futures.framework */; };
11-
B757AE7620B8A5BA00850F92 /* FutureValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = B757AE7320B8A5BA00850F92 /* FutureValue.swift */; };
12-
B757AE7720B8A5BA00850F92 /* FutureValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = B757AE7320B8A5BA00850F92 /* FutureValue.swift */; };
13-
B757AE7820B8A5BA00850F92 /* FutureValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = B757AE7320B8A5BA00850F92 /* FutureValue.swift */; };
14-
B757AE7920B8A5BA00850F92 /* FutureValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = B757AE7320B8A5BA00850F92 /* FutureValue.swift */; };
11+
B757AE7620B8A5BA00850F92 /* FutureResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = B757AE7320B8A5BA00850F92 /* FutureResult.swift */; };
12+
B757AE7720B8A5BA00850F92 /* FutureResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = B757AE7320B8A5BA00850F92 /* FutureResult.swift */; };
13+
B757AE7820B8A5BA00850F92 /* FutureResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = B757AE7320B8A5BA00850F92 /* FutureResult.swift */; };
14+
B757AE7920B8A5BA00850F92 /* FutureResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = B757AE7320B8A5BA00850F92 /* FutureResult.swift */; };
1515
B757AE7A20B8A5BA00850F92 /* DispatchQueue+Promise.swift in Sources */ = {isa = PBXBuildFile; fileRef = B757AE7420B8A5BA00850F92 /* DispatchQueue+Promise.swift */; };
1616
B757AE7B20B8A5BA00850F92 /* DispatchQueue+Promise.swift in Sources */ = {isa = PBXBuildFile; fileRef = B757AE7420B8A5BA00850F92 /* DispatchQueue+Promise.swift */; };
1717
B757AE7C20B8A5BA00850F92 /* DispatchQueue+Promise.swift in Sources */ = {isa = PBXBuildFile; fileRef = B757AE7420B8A5BA00850F92 /* DispatchQueue+Promise.swift */; };
@@ -52,7 +52,7 @@
5252
B757AE2A20B8924600850F92 /* Futures.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Futures.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5353
B757AE3720B8926D00850F92 /* Futures.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Futures.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5454
B757AE4420B8928200850F92 /* Futures.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Futures.framework; sourceTree = BUILT_PRODUCTS_DIR; };
55-
B757AE7320B8A5BA00850F92 /* FutureValue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FutureValue.swift; sourceTree = "<group>"; };
55+
B757AE7320B8A5BA00850F92 /* FutureResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FutureResult.swift; sourceTree = "<group>"; };
5656
B757AE7420B8A5BA00850F92 /* DispatchQueue+Promise.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DispatchQueue+Promise.swift"; sourceTree = "<group>"; };
5757
B757AE7520B8A5BA00850F92 /* Future.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Future.swift; sourceTree = "<group>"; };
5858
B757AE8420B8A5C700850F92 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -137,7 +137,7 @@
137137
B757AE7220B8A5BA00850F92 /* Future */ = {
138138
isa = PBXGroup;
139139
children = (
140-
B757AE7320B8A5BA00850F92 /* FutureValue.swift */,
140+
B757AE7320B8A5BA00850F92 /* FutureResult.swift */,
141141
B757AE7420B8A5BA00850F92 /* DispatchQueue+Promise.swift */,
142142
B757AE7520B8A5BA00850F92 /* Future.swift */,
143143
B79FF3AC20BC6D1E001A625C /* Promise.swift */,
@@ -483,7 +483,7 @@
483483
B757AE7E20B8A5BA00850F92 /* Future.swift in Sources */,
484484
B79FF3AD20BC6D1E001A625C /* Promise.swift in Sources */,
485485
B768073820C6C02E00402ECB /* FutureProvider.swift in Sources */,
486-
B757AE7620B8A5BA00850F92 /* FutureValue.swift in Sources */,
486+
B757AE7620B8A5BA00850F92 /* FutureResult.swift in Sources */,
487487
B757AE7A20B8A5BA00850F92 /* DispatchQueue+Promise.swift in Sources */,
488488
);
489489
runOnlyForDeploymentPostprocessing = 0;
@@ -503,7 +503,7 @@
503503
B79FF3B820BC6E34001A625C /* AnyFuture.swift in Sources */,
504504
B757AE7F20B8A5BA00850F92 /* Future.swift in Sources */,
505505
B79FF3AE20BC6D1E001A625C /* Promise.swift in Sources */,
506-
B757AE7720B8A5BA00850F92 /* FutureValue.swift in Sources */,
506+
B757AE7720B8A5BA00850F92 /* FutureResult.swift in Sources */,
507507
B757AE7B20B8A5BA00850F92 /* DispatchQueue+Promise.swift in Sources */,
508508
);
509509
runOnlyForDeploymentPostprocessing = 0;
@@ -515,7 +515,7 @@
515515
B79FF3B920BC6E34001A625C /* AnyFuture.swift in Sources */,
516516
B757AE8020B8A5BA00850F92 /* Future.swift in Sources */,
517517
B79FF3AF20BC6D1E001A625C /* Promise.swift in Sources */,
518-
B757AE7820B8A5BA00850F92 /* FutureValue.swift in Sources */,
518+
B757AE7820B8A5BA00850F92 /* FutureResult.swift in Sources */,
519519
B757AE7C20B8A5BA00850F92 /* DispatchQueue+Promise.swift in Sources */,
520520
);
521521
runOnlyForDeploymentPostprocessing = 0;
@@ -527,7 +527,7 @@
527527
B79FF3BA20BC6E34001A625C /* AnyFuture.swift in Sources */,
528528
B757AE8120B8A5BA00850F92 /* Future.swift in Sources */,
529529
B79FF3B020BC6D1E001A625C /* Promise.swift in Sources */,
530-
B757AE7920B8A5BA00850F92 /* FutureValue.swift in Sources */,
530+
B757AE7920B8A5BA00850F92 /* FutureResult.swift in Sources */,
531531
B757AE7D20B8A5BA00850F92 /* DispatchQueue+Promise.swift in Sources */,
532532
);
533533
runOnlyForDeploymentPostprocessing = 0;

Sources/Futures/Future.swift

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import Dispatch
22

3-
private enum FutureState<Value> {
3+
private enum FutureState<Result> {
44
case pending
5-
case finished(FutureValue<Value>)
5+
case finished(FutureResult<Result>)
66

7-
fileprivate func canTransition(to newState: FutureState<Value>) -> Bool {
7+
fileprivate func canTransition(to newState: FutureState<Result>) -> Bool {
88

99
switch (self, newState) {
1010
case (.pending, .finished):
@@ -39,13 +39,13 @@ public protocol AnyFutureObserver: class {
3939
/// - `Future<T>.whenRejected()`
4040
public final class FutureObserver<T>: AnyFutureObserver {
4141

42-
private let callback: (FutureValue<T>) -> Void
42+
private let callback: (FutureResult<T>) -> Void
4343

4444
private let queue: DispatchQueue
4545

4646
private weak var future: Future<T>?
4747

48-
fileprivate init(_ callback: @escaping (FutureValue<T>) -> Void, future: Future<T>, queue: DispatchQueue) {
48+
fileprivate init(_ callback: @escaping (FutureResult<T>) -> Void, future: Future<T>, queue: DispatchQueue) {
4949
self.callback = callback
5050
self.future = future
5151
self.queue = queue
@@ -57,7 +57,7 @@ public final class FutureObserver<T>: AnyFutureObserver {
5757
future?.removeObserver(self)
5858
}
5959

60-
fileprivate func invoke(_ value: FutureValue<T>) {
60+
fileprivate func invoke(_ value: FutureResult<T>) {
6161
queue.async {
6262
self.callback(value)
6363
}
@@ -136,8 +136,8 @@ public final class Future<T>: AnyFuture {
136136

137137
/// Creates a resolved future
138138
///
139-
/// - Parameter resolved: `FutureValue<T>`
140-
public init(resolved: FutureValue<T>) {
139+
/// - Parameter resolved: `FutureResult<T>`
140+
public init(resolved: FutureResult<T>) {
141141
state = .finished(resolved)
142142
}
143143

@@ -174,7 +174,7 @@ public final class Future<T>: AnyFuture {
174174
}
175175
}
176176

177-
fileprivate func setValue(_ value: FutureValue<T>) {
177+
fileprivate func setValue(_ value: FutureResult<T>) {
178178
stateQueue.sync(flags: .barrier) {
179179

180180
guard case .pending = state else {
@@ -223,6 +223,16 @@ public final class Future<T>: AnyFuture {
223223
return true
224224
}
225225
}
226+
227+
/// Indicates the result of the future.
228+
/// Returns `nil` if the future is not resolved yet.
229+
public var result: FutureResult<T>? {
230+
guard case .finished(let result) = state else {
231+
return nil
232+
}
233+
234+
return result
235+
}
226236
}
227237

228238
extension Future: Equatable {
@@ -530,12 +540,12 @@ public extension Future {
530540
///
531541
/// - Parameters:
532542
/// - queue: Dispatch queue to observe on.
533-
/// - callback: Callback invoked with the resolved `FutureValue<T>` of this future
543+
/// - callback: Callback invoked with the resolved `FutureResult<T>` of this future
534544
/// - Returns: A `FutureObserver<T>`, which can be used to remove the observer from this future.
535545
@discardableResult
536546
func whenResolved(
537547
on queue: DispatchQueue = .futures,
538-
callback: @escaping (FutureValue<T>) -> Void) -> FutureObserver<T> {
548+
callback: @escaping (FutureResult<T>) -> Void) -> FutureObserver<T> {
539549
let observer = FutureObserver<T>(callback, future: self, queue: queue)
540550

541551
self.addObserver(observer)
@@ -563,8 +573,8 @@ public extension Promise {
563573

564574
/// Resolves the promise, setting either a value or an error to this promise's `Future`
565575
///
566-
/// - Parameter result: `FutureValue<T>` to resolve with
567-
func resolve(_ result: FutureValue<T>) {
576+
/// - Parameter result: `FutureResult<T>` to resolve with
577+
func resolve(_ result: FutureResult<T>) {
568578
future.setValue(result)
569579
}
570580
}

Sources/Futures/FutureValue.swift renamed to Sources/Futures/FutureResult.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import Dispatch
22

3-
/// Value of a future, being either rejected with an error or fulfilled with a value.
3+
/// Result of a future, being either rejected with an error or fulfilled with a value.
44
///
5-
/// - fulfilled: A fulfilled future, with a value.
6-
/// - rejected: A rejected future, with an error.
7-
public enum FutureValue<T> {
5+
/// - fulfilled: A fulfilled future result, with a value.
6+
/// - rejected: A rejected future result, with an error.
7+
public enum FutureResult<T> {
88

99
/// The value is fulfilled
1010
case fulfilled(T)
1111

1212
/// The value is rejected
1313
case rejected(Error)
1414

15-
/// Creates a new `FutureValue<T>`, capturing the return value, or throw error of a function.
15+
/// Creates a new `FutureResult<T>`, capturing the return value, or throw error of a function.
1616
///
1717
/// - Parameter capturing: Function to invoke, resulting in an error or a value.
1818
public init(_ capturing: () throws -> T) {
@@ -23,14 +23,14 @@ public enum FutureValue<T> {
2323
}
2424
}
2525

26-
/// Creates a new fulfilled `FutureValue<T>`.
26+
/// Creates a new fulfilled `FutureResult<T>`.
2727
///
2828
/// - Parameter value: A fulfilled value.
2929
public init(_ value: T) {
3030
self = .fulfilled(value)
3131
}
3232

33-
/// Creates a new rejected `FutureValue<T>`.
33+
/// Creates a new rejected `FutureResult<T>`.
3434
///
3535
/// - Parameter error: A rejection error
3636
public init(_ error: Error) {
@@ -85,7 +85,7 @@ public enum FutureValue<T> {
8585
}
8686
}
8787

88-
/// The description of this `FutureValue<T>`
88+
/// The description of this `FutureResult<T>`
8989
public var description: String {
9090
switch self {
9191
case .fulfilled(let value):
@@ -96,8 +96,8 @@ public enum FutureValue<T> {
9696
}
9797
}
9898

99-
public extension FutureValue where T == Void {
100-
static var success: FutureValue {
99+
public extension FutureResult where T == Void {
100+
static var success: FutureResult {
101101
return .fulfilled(())
102102
}
103103
}

Sources/Futures/Promise.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ public func promise<T>(on queue: DispatchQueue = .futures, _ body: @escaping ()
2929
/// - Parameters:
3030
/// - type: Type of the future value.
3131
/// - queue: Dispatch queue to execute the callback on.
32-
/// - body: A function with a completion function as its parameter, taking a `FutureValue<T>`, which will be
32+
/// - body: A function with a completion function as its parameter, taking a `FutureResult<T>`, which will be
3333
/// used to resolve the future returned by this method.
34-
/// - value: `FutureValue<T>` to resolve the future with.
34+
/// - value: `FutureResult<T>` to resolve the future with.
3535
/// - Returns: A future that will receive the eventual value.
3636
public func promise<T>(
3737
_ type: T.Type,
3838
on queue: DispatchQueue = .futures,
39-
_ body: @escaping (@escaping (_ value: FutureValue<T>) -> Void) throws -> Void) -> Future<T> {
39+
_ body: @escaping (@escaping (_ value: FutureResult<T>) -> Void) throws -> Void) -> Future<T> {
4040

4141
let promise = Promise<T>()
4242

4343
queue.async {
4444
do {
45-
let completion = { (value: FutureValue<T>) in
45+
let completion = { (value: FutureResult<T>) in
4646
promise.resolve(value)
4747
}
4848

docs/Classes.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<a class="nav-group-name-link" href="Enums.html">Enumerations</a>
6666
<ul class="nav-group-tasks">
6767
<li class="nav-group-task">
68-
<a class="nav-group-task-link" href="Enums/FutureValue.html">FutureValue</a>
68+
<a class="nav-group-task-link" href="Enums/FutureResult.html">FutureResult</a>
6969
</li>
7070
</ul>
7171
</li>
@@ -81,10 +81,10 @@
8181
<a class="nav-group-name-link" href="Functions.html">Functions</a>
8282
<ul class="nav-group-tasks">
8383
<li class="nav-group-task">
84-
<a class="nav-group-task-link" href="Functions.html#/s:7Futures7promiseAA6FutureCyxGxm_So13DispatchQueueC2onyyAA0C5ValueOyxGcKctlF">promise(_:on:_:)</a>
84+
<a class="nav-group-task-link" href="Functions.html#/s:7Futures7promise_2on_AA6FutureCyxGxm_So17OS_dispatch_queueCyyAA0D6ResultOyxGcKctlF">promise(_:on:_:)</a>
8585
</li>
8686
<li class="nav-group-task">
87-
<a class="nav-group-task-link" href="Functions.html#/s:7Futures7promiseAA6FutureCyxGSo13DispatchQueueC2on_xyKctlF">promise(on:_:)</a>
87+
<a class="nav-group-task-link" href="Functions.html#/s:7Futures7promise2on_AA6FutureCyxGSo17OS_dispatch_queueC_xyKctlF">promise(on:_:)</a>
8888
</li>
8989
</ul>
9090
</li>
@@ -252,7 +252,7 @@ <h4>Declaration</h4>
252252
</article>
253253
</div>
254254
<section class="footer">
255-
<p>&copy; 2018 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2018-09-01)</p>
255+
<p>&copy; 2018 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2018-09-26)</p>
256256
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.9.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
257257
</section>
258258
</body>

0 commit comments

Comments
 (0)