Skip to content

Conversation

fabianfett
Copy link
Member

When having a state machine inside the NIOLoopBoundBox we currently check the EL when reading and writing. This is unnecessary. Because of this PR introduces a new withValue method, that allows users to read and write the value inside the NIOLoopBoundBox while only paying the cost for the EL check once.

@fabianfett fabianfett added the 🆕 semver/minor Adds new public API. label Sep 30, 2025
@fabianfett fabianfett requested a review from glbrntt September 30, 2025 15:56
/// - Returns: The value returned by the `handler` closure.
/// - Note: This method is particularly useful when you need to perform read and write operations
/// on the value because it reduces the on EventLoop checks.
public func withValue<T, E: Error>(_ handler: (inout Value) throws(E) -> T) throws(E) -> T {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use Result and Failure instead of T and E?

Comment on lines 194 to 196
var value = self._value
defer { self._value = value }
return try handler(&value)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we just do try handler(&self._value)?

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.

Blocking the merge of this until #3393 is merged so we don't accidentally add back in some #if compiler that are hard to remove.

@Lukasa Lukasa self-requested a review October 6, 2025 10:19
@Lukasa
Copy link
Contributor

Lukasa commented Oct 6, 2025

No longer blocked, but please remove the compiler guards that are now unneeded.

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.

3 participants