diff --git a/Futures.xcodeproj/project.pbxproj b/Futures.xcodeproj/project.pbxproj index 7d3756a..4f460b6 100644 --- a/Futures.xcodeproj/project.pbxproj +++ b/Futures.xcodeproj/project.pbxproj @@ -22,7 +22,7 @@ /* Begin PBXBuildFile section */ OBJ_30 /* AnyFuture.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_9 /* AnyFuture.swift */; }; - OBJ_31 /* DispatchQueue+Promise.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_10 /* DispatchQueue+Promise.swift */; }; + OBJ_31 /* DispatchQueue+Futures.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_10 /* DispatchQueue+Futures.swift */; }; OBJ_32 /* Future.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_11 /* Future.swift */; }; OBJ_33 /* Promise.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_12 /* Promise.swift */; }; OBJ_34 /* PromisesExtended.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_13 /* PromisesExtended.swift */; }; @@ -51,7 +51,7 @@ /* Begin PBXFileReference section */ "Futures::Futures::Product" /* Futures.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Futures.framework; sourceTree = BUILT_PRODUCTS_DIR; }; "Futures::FuturesTests::Product" /* FuturesTests.xctest */ = {isa = PBXFileReference; lastKnownFileType = file; path = FuturesTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - OBJ_10 /* DispatchQueue+Promise.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DispatchQueue+Promise.swift"; sourceTree = ""; }; + OBJ_10 /* DispatchQueue+Futures.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DispatchQueue+Futures.swift"; sourceTree = ""; }; OBJ_11 /* Future.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Future.swift; sourceTree = ""; }; OBJ_12 /* Promise.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Promise.swift; sourceTree = ""; }; OBJ_13 /* PromisesExtended.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PromisesExtended.swift; sourceTree = ""; }; @@ -110,7 +110,7 @@ name = Products; sourceTree = BUILT_PRODUCTS_DIR; }; - OBJ_5 /* */ = { + OBJ_5 = { isa = PBXGroup; children = ( OBJ_6 /* Package.swift */, @@ -123,7 +123,6 @@ OBJ_23 /* LICENSE */, OBJ_24 /* README.md */, ); - name = ""; sourceTree = ""; }; OBJ_7 /* Sources */ = { @@ -138,7 +137,7 @@ isa = PBXGroup; children = ( OBJ_9 /* AnyFuture.swift */, - OBJ_10 /* DispatchQueue+Promise.swift */, + OBJ_10 /* DispatchQueue+Futures.swift */, OBJ_11 /* Future.swift */, OBJ_12 /* Promise.swift */, OBJ_13 /* PromisesExtended.swift */, @@ -214,7 +213,7 @@ knownRegions = ( en, ); - mainGroup = OBJ_5 /* */; + mainGroup = OBJ_5; productRefGroup = OBJ_17 /* Products */; projectDirPath = ""; projectRoot = ""; @@ -254,7 +253,7 @@ buildActionMask = 0; files = ( OBJ_30 /* AnyFuture.swift in Sources */, - OBJ_31 /* DispatchQueue+Promise.swift in Sources */, + OBJ_31 /* DispatchQueue+Futures.swift in Sources */, OBJ_32 /* Future.swift in Sources */, OBJ_33 /* Promise.swift in Sources */, OBJ_34 /* PromisesExtended.swift in Sources */, diff --git a/Sources/Futures/DispatchQueue+Promise.swift b/Sources/Futures/DispatchQueue+Futures.swift similarity index 100% rename from Sources/Futures/DispatchQueue+Promise.swift rename to Sources/Futures/DispatchQueue+Futures.swift diff --git a/Sources/Futures/Future.swift b/Sources/Futures/Future.swift index 176be21..bbf2d18 100644 --- a/Sources/Futures/Future.swift +++ b/Sources/Futures/Future.swift @@ -294,8 +294,8 @@ public extension Future { /// :nodoc: @available(*, deprecated, renamed: "flatMap") func then( - on queue: DispatchQueue = .futures, - callback: @escaping (_ value: Value) -> Future) -> Future { + on queue: DispatchQueue = .futures, + callback: @escaping (_ value: Value) -> Future) -> Future { flatMap(on: queue, callback: callback) } @@ -336,8 +336,8 @@ public extension Future { /// :nodoc: @available(*, deprecated, renamed: "flatMapIfRejected") func thenIfRejected( - on queue: DispatchQueue = .futures, - callback: @escaping(Error) -> Future) -> Future { + on queue: DispatchQueue = .futures, + callback: @escaping(Error) -> Future) -> Future { flatMapIfRejected(on: queue, callback: callback) } @@ -366,8 +366,8 @@ public extension Future { /// :nodoc: @available(*, deprecated, renamed: "flatMapThrowing") func thenThrowing( - on queue: DispatchQueue = .futures, - callback: @escaping (Value) throws -> NewValue) -> Future { + on queue: DispatchQueue = .futures, + callback: @escaping (Value) throws -> NewValue) -> Future { flatMapThrowing(on: queue, callback: callback) } @@ -440,6 +440,14 @@ public extension Future { func mapIfRejected(on queue: DispatchQueue = .futures, callback: @escaping (Error) -> Value) -> Future { return recover(on: queue, callback: callback) } + + func print(on queue: DispatchQueue = .futures) -> Future { + whenFulfilled { value in + Swift.print(value) + } + + return self + } } public extension Future { @@ -492,11 +500,11 @@ public extension Future { with combiningFunction: @escaping (Value, NewValue) -> Future) -> Future where S.Element == Future { - return futures.reduce(self) { future1, future2 in - return future1.and(future2, on: queue).flatMap(on: queue) { value1, value2 in - return combiningFunction(value1, value2) + return futures.reduce(self) { future1, future2 in + return future1.and(future2, on: queue).flatMap(on: queue) { value1, value2 in + return combiningFunction(value1, value2) + } } - } } /// Returns a new `Future` that fires only when all the provided `Future`s have been resolved. @@ -521,11 +529,11 @@ public extension Future { nextPartialResult: @escaping (Value, NewValue) -> Value) -> Future where S.Element == Future { - let initialResult = Future(fulfilledWith: initialResult) + let initialResult = Future(fulfilledWith: initialResult) - return initialResult.fold(futures, on: queue) { value1, value2 in - return Future(fulfilledWith: nextPartialResult(value1, value2)) - } + return initialResult.fold(futures, on: queue) { value1, value2 in + return Future(fulfilledWith: nextPartialResult(value1, value2)) + } } /// Returns a new `Future` that will resolve with result of this `Future` **after** @@ -599,18 +607,9 @@ public extension Future { /// - Returns: A future that will receive the eventual value. @discardableResult func discard(on queue: DispatchQueue = .futures) -> Future { - - let promise = Promise() - - whenFulfilled(on: queue) { _ in - promise.fulfill() - } - - whenRejected { error in - promise.reject(error) + map(on: queue) { _ in + return () } - - return promise.future } }