-
Notifications
You must be signed in to change notification settings - Fork 656
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Support hopping event loops with EventLoopFuture #177
Conversation
Sources/NIO/EventLoopFuture.swift
Outdated
/// - parameters: | ||
/// - target: The `EventLoop` that the returned `EventLoopFuture` will run on. | ||
/// - returns: An `EventLoopFuture` whose callbacks run on `target` instead of the original loop. | ||
func on(eventLoop target: EventLoop) -> EventLoopFuture<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.
I'm not sure about this name. Maybe hopTo(eventLoop:)
?
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.
Like this PR! What about just hop(eventLoop: EventLoop)
. So future.hop(eventLoop: otherEL)
.
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.
I think I would either call it hopTo(eventLoop:)
or just use hopOn(eventLoop:)
.
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.
@weissi Any objection to hopTo
?
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.
Nope, sounds good to me
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.
Approved. Would prefer a name change but happy as is.
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.
LGTM... just the naming comment
Sources/NIO/EventLoopFuture.swift
Outdated
/// - parameters: | ||
/// - target: The `EventLoop` that the returned `EventLoopFuture` will run on. | ||
/// - returns: An `EventLoopFuture` whose callbacks run on `target` instead of the original loop. | ||
func on(eventLoop target: EventLoop) -> EventLoopFuture<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.
I think I would either call it hopTo(eventLoop:)
or just use hopOn(eventLoop:)
.
Motivation: A somewhat common requirement when working with chains of futures is needing to hop from one event loop to another. This is particularly common when relying on the fact that EventLoopFuture will synchronize with the event loop that created it: you often want to rely on that implicit locking, rather than use Dispatch or Lock to achieve the same effect. While doing this hop requires relatively little code, it's not necessarily totally apparent to new users how they would do it. Additionally, the most naive implementation incurs the overhead of allocations and reference counting in cases where it's not necessary (e.g. when you have only one event loop, or when both work items are being scheduled on the same event loop). For this reason, we should have a nice concise way for a user to request this behaviour and get a relatively performant implementation of the behaviour. Modifications: Added EventLoopFuture<T>.on(eventLoop:). Changed AcceptHandler to use the new method rather than its (slower) alternative. Result: Users will have an easier time working with EventLoopFutures.
62c746b
to
18056d9
Compare
Ok, renamed, and also updated |
@Lukasa thanks! Shipped :) |
Motivation: A somewhat common requirement when working with chains of futures is needing to hop from one event loop to another. This is particularly common when relying on the fact that EventLoopFuture will synchronize with the event loop that created it: you often want to rely on that implicit locking, rather than use Dispatch or Lock to achieve the same effect. While doing this hop requires relatively little code, it's not necessarily totally apparent to new users how they would do it. Additionally, the most naive implementation incurs the overhead of allocations and reference counting in cases where it's not necessary (e.g. when you have only one event loop, or when both work items are being scheduled on the same event loop). For this reason, we should have a nice concise way for a user to request this behaviour and get a relatively performant implementation of the behaviour. Modifications: Added EventLoopFuture<T>.on(eventLoop:). Changed AcceptHandler to use the new method rather than its (slower) alternative. Result: Users will have an easier time working with EventLoopFutures.
Motivation Currently we don't confirm that the decompression has completed successfully. This means that we can incorrectly spin forever attempting to decompress past the end of a message, and that we can fail to notice that a message is truncated. Neither of these is good. Modifications Propagate the message zlib gives us as to whether or not decompression is done, and keep track of it. Add some tests written by @vojtarylko to validate the behaviour. Result Correctly police the bounds of the messages. Resolves apple#175 and apple#176.
Motivation:
A somewhat common requirement when working with chains of futures
is needing to hop from one event loop to another. This is particularly
common when relying on the fact that EventLoopFuture will synchronize
with the event loop that created it: you often want to rely on that
implicit locking, rather than use Dispatch or Lock to achieve the
same effect.
While doing this hop requires relatively little code, it's not
necessarily totally apparent to new users how they would do it.
Additionally, the most naive implementation incurs the overhead of
allocations and reference counting in cases where it's not necessary
(e.g. when you have only one event loop, or when both work items are
being scheduled on the same event loop).
For this reason, we should have a nice concise way for a user to
request this behaviour and get a relatively performant implementation
of the behaviour.
Modifications:
Added EventLoopFuture.on(eventLoop:).
Changed AcceptHandler to use the new method rather than its (slower)
alternative.
Result:
Users will have an easier time working with EventLoopFutures.