Skip to content

Commit f47a292

Browse files
committed
Rename file, update discard member
1 parent 1424967 commit f47a292

File tree

3 files changed

+30
-32
lines changed

3 files changed

+30
-32
lines changed

Futures.xcodeproj/project.pbxproj

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
/* Begin PBXBuildFile section */
2424
OBJ_30 /* AnyFuture.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_9 /* AnyFuture.swift */; };
25-
OBJ_31 /* DispatchQueue+Promise.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_10 /* DispatchQueue+Promise.swift */; };
25+
OBJ_31 /* DispatchQueue+Futures.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_10 /* DispatchQueue+Futures.swift */; };
2626
OBJ_32 /* Future.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_11 /* Future.swift */; };
2727
OBJ_33 /* Promise.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_12 /* Promise.swift */; };
2828
OBJ_34 /* PromisesExtended.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_13 /* PromisesExtended.swift */; };
@@ -51,7 +51,7 @@
5151
/* Begin PBXFileReference section */
5252
"Futures::Futures::Product" /* Futures.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Futures.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5353
"Futures::FuturesTests::Product" /* FuturesTests.xctest */ = {isa = PBXFileReference; lastKnownFileType = file; path = FuturesTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
54-
OBJ_10 /* DispatchQueue+Promise.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DispatchQueue+Promise.swift"; sourceTree = "<group>"; };
54+
OBJ_10 /* DispatchQueue+Futures.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DispatchQueue+Futures.swift"; sourceTree = "<group>"; };
5555
OBJ_11 /* Future.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Future.swift; sourceTree = "<group>"; };
5656
OBJ_12 /* Promise.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Promise.swift; sourceTree = "<group>"; };
5757
OBJ_13 /* PromisesExtended.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PromisesExtended.swift; sourceTree = "<group>"; };
@@ -110,7 +110,7 @@
110110
name = Products;
111111
sourceTree = BUILT_PRODUCTS_DIR;
112112
};
113-
OBJ_5 /* */ = {
113+
OBJ_5 = {
114114
isa = PBXGroup;
115115
children = (
116116
OBJ_6 /* Package.swift */,
@@ -123,7 +123,6 @@
123123
OBJ_23 /* LICENSE */,
124124
OBJ_24 /* README.md */,
125125
);
126-
name = "";
127126
sourceTree = "<group>";
128127
};
129128
OBJ_7 /* Sources */ = {
@@ -138,7 +137,7 @@
138137
isa = PBXGroup;
139138
children = (
140139
OBJ_9 /* AnyFuture.swift */,
141-
OBJ_10 /* DispatchQueue+Promise.swift */,
140+
OBJ_10 /* DispatchQueue+Futures.swift */,
142141
OBJ_11 /* Future.swift */,
143142
OBJ_12 /* Promise.swift */,
144143
OBJ_13 /* PromisesExtended.swift */,
@@ -214,7 +213,7 @@
214213
knownRegions = (
215214
en,
216215
);
217-
mainGroup = OBJ_5 /* */;
216+
mainGroup = OBJ_5;
218217
productRefGroup = OBJ_17 /* Products */;
219218
projectDirPath = "";
220219
projectRoot = "";
@@ -254,7 +253,7 @@
254253
buildActionMask = 0;
255254
files = (
256255
OBJ_30 /* AnyFuture.swift in Sources */,
257-
OBJ_31 /* DispatchQueue+Promise.swift in Sources */,
256+
OBJ_31 /* DispatchQueue+Futures.swift in Sources */,
258257
OBJ_32 /* Future.swift in Sources */,
259258
OBJ_33 /* Promise.swift in Sources */,
260259
OBJ_34 /* PromisesExtended.swift in Sources */,

Sources/Futures/Future.swift

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ public extension Future {
294294
/// :nodoc:
295295
@available(*, deprecated, renamed: "flatMap")
296296
func then<NewValue>(
297-
on queue: DispatchQueue = .futures,
298-
callback: @escaping (_ value: Value) -> Future<NewValue>) -> Future<NewValue> {
297+
on queue: DispatchQueue = .futures,
298+
callback: @escaping (_ value: Value) -> Future<NewValue>) -> Future<NewValue> {
299299
flatMap(on: queue, callback: callback)
300300
}
301301

@@ -336,8 +336,8 @@ public extension Future {
336336
/// :nodoc:
337337
@available(*, deprecated, renamed: "flatMapIfRejected")
338338
func thenIfRejected(
339-
on queue: DispatchQueue = .futures,
340-
callback: @escaping(Error) -> Future<Value>) -> Future<Value> {
339+
on queue: DispatchQueue = .futures,
340+
callback: @escaping(Error) -> Future<Value>) -> Future<Value> {
341341
flatMapIfRejected(on: queue, callback: callback)
342342
}
343343

@@ -366,8 +366,8 @@ public extension Future {
366366
/// :nodoc:
367367
@available(*, deprecated, renamed: "flatMapThrowing")
368368
func thenThrowing<NewValue>(
369-
on queue: DispatchQueue = .futures,
370-
callback: @escaping (Value) throws -> NewValue) -> Future<NewValue> {
369+
on queue: DispatchQueue = .futures,
370+
callback: @escaping (Value) throws -> NewValue) -> Future<NewValue> {
371371
flatMapThrowing(on: queue, callback: callback)
372372
}
373373

@@ -440,6 +440,14 @@ public extension Future {
440440
func mapIfRejected(on queue: DispatchQueue = .futures, callback: @escaping (Error) -> Value) -> Future<Value> {
441441
return recover(on: queue, callback: callback)
442442
}
443+
444+
func print(on queue: DispatchQueue = .futures) -> Future<Value> {
445+
whenFulfilled { value in
446+
Swift.print(value)
447+
}
448+
449+
return self
450+
}
443451
}
444452

445453
public extension Future {
@@ -492,11 +500,11 @@ public extension Future {
492500
with combiningFunction: @escaping (Value, NewValue) -> Future<Value>) -> Future<Value>
493501
where S.Element == Future<NewValue> {
494502

495-
return futures.reduce(self) { future1, future2 in
496-
return future1.and(future2, on: queue).flatMap(on: queue) { value1, value2 in
497-
return combiningFunction(value1, value2)
503+
return futures.reduce(self) { future1, future2 in
504+
return future1.and(future2, on: queue).flatMap(on: queue) { value1, value2 in
505+
return combiningFunction(value1, value2)
506+
}
498507
}
499-
}
500508
}
501509

502510
/// Returns a new `Future<Value>` that fires only when all the provided `Future<NewValue>`s have been resolved.
@@ -521,11 +529,11 @@ public extension Future {
521529
nextPartialResult: @escaping (Value, NewValue) -> Value) -> Future<Value>
522530
where S.Element == Future<NewValue> {
523531

524-
let initialResult = Future<Value>(fulfilledWith: initialResult)
532+
let initialResult = Future<Value>(fulfilledWith: initialResult)
525533

526-
return initialResult.fold(futures, on: queue) { value1, value2 in
527-
return Future(fulfilledWith: nextPartialResult(value1, value2))
528-
}
534+
return initialResult.fold(futures, on: queue) { value1, value2 in
535+
return Future(fulfilledWith: nextPartialResult(value1, value2))
536+
}
529537
}
530538

531539
/// Returns a new `Future<Value>` that will resolve with result of this `Future` **after**
@@ -599,18 +607,9 @@ public extension Future {
599607
/// - Returns: A future that will receive the eventual value.
600608
@discardableResult
601609
func discard(on queue: DispatchQueue = .futures) -> Future<Void> {
602-
603-
let promise = Promise<Void>()
604-
605-
whenFulfilled(on: queue) { _ in
606-
promise.fulfill()
607-
}
608-
609-
whenRejected { error in
610-
promise.reject(error)
610+
map(on: queue) { _ in
611+
return ()
611612
}
612-
613-
return promise.future
614613
}
615614
}
616615

0 commit comments

Comments
 (0)