-
Notifications
You must be signed in to change notification settings - Fork 704
Quality of Life: Add NIOLoopBoundBox.withValue
#3385
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
base: main
Are you sure you want to change the base?
Conversation
Sources/NIOCore/NIOLoopBound.swift
Outdated
/// - 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 { |
There was a problem hiding this comment.
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
?
Sources/NIOCore/NIOLoopBound.swift
Outdated
var value = self._value | ||
defer { self._value = value } | ||
return try handler(&value) |
There was a problem hiding this comment.
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)
?
There was a problem hiding this 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.
No longer blocked, but please remove the compiler guards that are now unneeded. |
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.