Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement: pass down file/line in makeFutureWithTask #2711

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Sources/NIOCore/AsyncAwaitSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,32 @@ struct AsyncSequenceFromIterator<AsyncIterator: AsyncIteratorProtocol>: AsyncSeq

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension EventLoop {
@available(*, deprecated, renamed: "makeFutureWithResultOfTask", message: "Prefer makeFutureWithResultOfTask as it will track the original creator of the promise.")
@inlinable
public func makeFutureWithTask<Return>(_ body: @Sendable @escaping () async throws -> Return) -> EventLoopFuture<Return> {
let promise = self.makePromise(of: Return.self)
promise.completeWithTask(body)
return promise.futureResult
}
}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension EventLoop {
/// Make a future whose body runs in an `async` function `body`.
///
/// This function can be used to bridge the `async` world into an `EventLoopFuture`.
///
/// - parameters:
/// - body: The `async` function to run.
/// - returns: A `Future` which completes when `body` finishes running.
@inlinable
public func makeFutureWithResultOfTask<Return>(
file: StaticString = #fileID,
line: UInt = #line,
_ body: @Sendable @escaping () async throws -> Return
) -> EventLoopFuture<Return> {
let promise = self.makePromise(of: Return.self, file: file, line: line)
promise.completeWithTask(body)
return promise.futureResult
}
}