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

Give NIOLoopBoundBox a sending off-EL initialiser once compiler is ready #2754

Open
weissi opened this issue Jun 26, 2024 · 0 comments · May be fixed by #3091
Open

Give NIOLoopBoundBox a sending off-EL initialiser once compiler is ready #2754

weissi opened this issue Jun 26, 2024 · 0 comments · May be fixed by #3091

Comments

@weissi
Copy link
Member

weissi commented Jun 26, 2024

https://github.com/swiftlang/swift-evolution/blob/main/proposals/0430-transferring-parameters-and-results.md will be useful to construct NIOLoopBoundBox with a non-Sendable value off EL.

But the compiler isn't ready quite yet.

This is a followup for #2753 (which allows Sendable values)

#if compiler(>=6.0) // `sending` is >= 6.0
extension NIOLoopBoundBox {
    /// Initialise a ``NIOLoopBoundBox`` by `sending` (i.e. transferring) a value, validly callable off `eventLoop`.
    ///
    /// Contrary to ``init(_:eventLoop:)``, this method can be called off `eventLoop` because we are `sending` the value across the isolation domain.
    /// Because we're `sending` `value`, we just need to protect it against mutations (because nothing else can have access to it anymore).
    public static func makeBoxSendingValue(
        _ value: sending Value,
        as: Value.Type = Value.self,
        eventLoop: EventLoop
    ) -> NIOLoopBoundBox<Value> {
        ...
    }
}
#endif
natikgadzhi added a commit to natikgadzhi/swift-nio that referenced this issue Jan 26, 2025
Motivation:

This closes apple#2754. It's a follow-up for apple#2753 that adds a way to `makeLoopBoundBox` by sendin a value,
leaning into Swift 6 concurrency!

Modifications:

- Adds `makeBoxSendingValue`. Can't take the credit, @weissi wrote it in the issue.
- Adds a test for it.

Result:

Nice NIOLoopBoundBox API for Swift 6.
@natikgadzhi natikgadzhi linked a pull request Jan 26, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant