Skip to content

Commit

Permalink
chore: Remove unnecessary funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
NeedleInAJayStack committed Jan 16, 2025
1 parent a5a86cd commit 3f347ae
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 35 deletions.
2 changes: 1 addition & 1 deletion Sources/GraphQL/Execution/Execute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ func completeValue(
}
}

return result.flatMap(to: Any?.self) { result -> Future<Any?> in
return result.tryFlatMap { result throws -> Future<Any?> in
// If result value is null-ish (nil or .null) then return .null.
guard let result = result, let r = unwrap(result) else {
return exeContext.eventLoopGroup.next().makeSucceededFuture(nil)
Expand Down
34 changes: 0 additions & 34 deletions Sources/GraphQL/Utilities/NIO+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ public extension Collection {
}
}

extension Collection {
func flatMap<S, T>(
to _: T.Type,
on eventLoopGroup: EventLoopGroup,
_ callback: @escaping ([S]) throws -> Future<T>
) -> Future<T> where Element == Future<S> {
return flatten(on: eventLoopGroup).flatMap(to: T.self, callback)
}
}

extension Dictionary where Value: FutureType {
func flatten(on eventLoopGroup: EventLoopGroup) -> Future<[Key: Value.Expectation]> {
// create array of futures with (key,value) tuple
Expand Down Expand Up @@ -63,30 +53,6 @@ extension OrderedDictionary where Value: FutureType {
}
}

extension Future {
func flatMap<T>(
to _: T.Type = T.self,
_ callback: @escaping (Expectation) throws -> Future<T>
) -> Future<T> {
let promise = eventLoop.makePromise(of: T.self)

whenSuccess { expectation in
do {
let mapped = try callback(expectation)
mapped.cascade(to: promise)
} catch {
promise.fail(error)
}
}

whenFailure { error in
promise.fail(error)
}

return promise.futureResult
}
}

public protocol FutureType {
associatedtype Expectation
func whenSuccess(_ callback: @escaping @Sendable (Expectation) -> Void)
Expand Down

0 comments on commit 3f347ae

Please sign in to comment.