Skip to content

Commit

Permalink
Rename file, update discard member
Browse files Browse the repository at this point in the history
  • Loading branch information
davidask committed Jun 11, 2020
1 parent 1424967 commit f47a292
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 32 deletions.
13 changes: 6 additions & 7 deletions Futures.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 = "<group>"; };
OBJ_10 /* DispatchQueue+Futures.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DispatchQueue+Futures.swift"; sourceTree = "<group>"; };
OBJ_11 /* Future.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Future.swift; sourceTree = "<group>"; };
OBJ_12 /* Promise.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Promise.swift; sourceTree = "<group>"; };
OBJ_13 /* PromisesExtended.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PromisesExtended.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -110,7 +110,7 @@
name = Products;
sourceTree = BUILT_PRODUCTS_DIR;
};
OBJ_5 /* */ = {
OBJ_5 = {
isa = PBXGroup;
children = (
OBJ_6 /* Package.swift */,
Expand All @@ -123,7 +123,6 @@
OBJ_23 /* LICENSE */,
OBJ_24 /* README.md */,
);
name = "";
sourceTree = "<group>";
};
OBJ_7 /* Sources */ = {
Expand All @@ -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 */,
Expand Down Expand Up @@ -214,7 +213,7 @@
knownRegions = (
en,
);
mainGroup = OBJ_5 /* */;
mainGroup = OBJ_5;
productRefGroup = OBJ_17 /* Products */;
projectDirPath = "";
projectRoot = "";
Expand Down Expand Up @@ -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 */,
Expand Down
File renamed without changes.
49 changes: 24 additions & 25 deletions Sources/Futures/Future.swift
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ public extension Future {
/// :nodoc:
@available(*, deprecated, renamed: "flatMap")
func then<NewValue>(
on queue: DispatchQueue = .futures,
callback: @escaping (_ value: Value) -> Future<NewValue>) -> Future<NewValue> {
on queue: DispatchQueue = .futures,
callback: @escaping (_ value: Value) -> Future<NewValue>) -> Future<NewValue> {
flatMap(on: queue, callback: callback)
}

Expand Down Expand Up @@ -336,8 +336,8 @@ public extension Future {
/// :nodoc:
@available(*, deprecated, renamed: "flatMapIfRejected")
func thenIfRejected(
on queue: DispatchQueue = .futures,
callback: @escaping(Error) -> Future<Value>) -> Future<Value> {
on queue: DispatchQueue = .futures,
callback: @escaping(Error) -> Future<Value>) -> Future<Value> {
flatMapIfRejected(on: queue, callback: callback)
}

Expand Down Expand Up @@ -366,8 +366,8 @@ public extension Future {
/// :nodoc:
@available(*, deprecated, renamed: "flatMapThrowing")
func thenThrowing<NewValue>(
on queue: DispatchQueue = .futures,
callback: @escaping (Value) throws -> NewValue) -> Future<NewValue> {
on queue: DispatchQueue = .futures,
callback: @escaping (Value) throws -> NewValue) -> Future<NewValue> {
flatMapThrowing(on: queue, callback: callback)
}

Expand Down Expand Up @@ -440,6 +440,14 @@ public extension Future {
func mapIfRejected(on queue: DispatchQueue = .futures, callback: @escaping (Error) -> Value) -> Future<Value> {
return recover(on: queue, callback: callback)
}

func print(on queue: DispatchQueue = .futures) -> Future<Value> {
whenFulfilled { value in
Swift.print(value)
}

return self
}
}

public extension Future {
Expand Down Expand Up @@ -492,11 +500,11 @@ public extension Future {
with combiningFunction: @escaping (Value, NewValue) -> Future<Value>) -> Future<Value>
where S.Element == Future<NewValue> {

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<Value>` that fires only when all the provided `Future<NewValue>`s have been resolved.
Expand All @@ -521,11 +529,11 @@ public extension Future {
nextPartialResult: @escaping (Value, NewValue) -> Value) -> Future<Value>
where S.Element == Future<NewValue> {

let initialResult = Future<Value>(fulfilledWith: initialResult)
let initialResult = Future<Value>(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<Value>` that will resolve with result of this `Future` **after**
Expand Down Expand Up @@ -599,18 +607,9 @@ public extension Future {
/// - Returns: A future that will receive the eventual value.
@discardableResult
func discard(on queue: DispatchQueue = .futures) -> Future<Void> {

let promise = Promise<Void>()

whenFulfilled(on: queue) { _ in
promise.fulfill()
}

whenRejected { error in
promise.reject(error)
map(on: queue) { _ in
return ()
}

return promise.future
}
}

Expand Down

0 comments on commit f47a292

Please sign in to comment.