Skip to content
Merged
Changes from 4 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
17 changes: 16 additions & 1 deletion Sources/NIOCore/AsyncChannel/AsyncChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,25 @@ public struct NIOAsyncChannel<Inbound: Sendable, Outbound: Sendable>: Sendable {
///
/// - Important: After this method returned the underlying ``Channel`` will be closed.
///
/// - Parameter body: A closure that gets scoped access to the inbound and outbound.
/// - Parameter: body: A closure that gets scoped access to the inbound and outbound.
public func executeThenClose<Result>(
_ body: (_ inbound: NIOAsyncChannelInboundStream<Inbound>, _ outbound: NIOAsyncChannelOutboundWriter<Outbound>)
async throws -> Result
) async throws -> Result {
try await executeThenClose(isolatedTo: nil, body)
}

/// Provides scoped access to the inbound and outbound side of the underlying ``Channel``.
///
/// - Important: After this method returned the underlying ``Channel`` will be closed.
///
/// - Parameter:
/// - actor: actor where this function should be isolated to
/// - body: A closure that gets scoped access to the inbound and outbound.
public func executeThenClose<Result>(
isolatedTo actor: isolated (any Actor)?,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We seem to have dropped the defaulted parameter here which I think we want.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is the compiler picking the right func if we default this parameter (i.e. if you call executeThenClose { ... } are we calling the old version, or the one defaulting isolation?).
We could use @_disfavoredOverload, but have we agreed that is the route we generally want to take?

Specifically in this case, if what we want is to enable adopters to use executeThenClose from actors, I don't think it's particularly bad to have to explicitly pass self as isolation, as it makes it clear you want to run this on the actor, even though you're awaiting and would otherwise be hopping off the isolation domain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As spoken offline, we decided to favour the use of @_disfavoredOverload with this API. I'll change the code.

_ body: (_ inbound: NIOAsyncChannelInboundStream<Inbound>, _ outbound: NIOAsyncChannelOutboundWriter<Outbound>)
async throws -> Result
) async throws -> Result {
let result: Result
do {
Expand Down
Loading