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

Add channel initializer closure to NIOAsyncTestingChannel.init #3053

Merged
merged 1 commit into from
Jan 13, 2025

Conversation

hamzahrmalik
Copy link
Contributor

Since nio 2.78, adding handlers to a pipeline requires the handlers to be sendable.

That makes the NIOAsyncTestingChannel.init(handlers:loop:) function cumbersome, because you cannot create handlers and then call the function (unless your handlers are Sendable) even if you never use the handlers elsewhere.

This PR adds a new initializer which takes a closure. The closure is run on-loop before the channel is registered. This means we can do:

let channel = try await NIOAsyncTestingChannel {
    let handler = MyUnsendableHandler()
    try $0.pipeline.syncOperations.addHandler(handler)
}

@Lukasa Lukasa added the 🆕 semver/minor Adds new public API. label Jan 13, 2025
Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Nice one, thanks @hamzahrmalik!

@Lukasa Lukasa merged commit 329ef54 into apple:main Jan 13, 2025
34 of 36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants