-
Notifications
You must be signed in to change notification settings - Fork 41
Add some NIO sugar to ServiceLifecycle.start() #72
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 some NIO sugar to ServiceLifecycle.start() #72
Conversation
thanks @fabianfett <3 |
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.
Oh boy, I missed to "Submit review" yesterday, sorry -_-''
Late, but I have concerns here so submitting now; please have a look @fabianfett
|
||
extension ServiceLifecycle { | ||
/// Starts the provided `LifecycleItem` array. | ||
/// Startup is performed in the order of items provided. |
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 we call them tasks? (LifecycleTask
) so the items wording is wording consistent here?
- /// Startup is performed in the order of items provided.
+ /// Startup is performed in the order of tasks provided.
/// | ||
/// - parameters: | ||
/// - eventLoop: The `eventLoop` which is used to generate the `EventLoopFuture` that is returned. After the start the future is fulfilled: | ||
func start(on eventLoop: EventLoop) -> EventLoopFuture<Void> { |
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 kind of wonder if this has the expected semantics from looking at this signature...
The method reads as "start on eventloop" which to me implies that lifecycle tasks will execute on that event loop, but they won't! they'd run on some dispatch queue anyway and only the future is completed/created from the loop.
Should this rather perform a synchronous start()
from inside of the passed in event loop (and also complete the promise as it does correctly)?
eventLoop.execute {
do {
self._start()
// we'd need a new start impl, as the only existing one assumes it must run on a dispatch queue
} catch { promise.fail(error) }
promise.succeed(())
}
in order to be true to its name?
--
Say, someone writes an app and does not synchronize any of their initialization because they assume "it's all on the exact same EL so I don't need to" -- would the current signature lead them down to accidentally actually do have concurrency issues during init?
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.
this is a good observation. in practice the lifecycle library always dispatches the start/stop calls onto a dispatch queue, as such naming the argument "on" could be confusing/misleading. do we have alternative proposals?
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 was thinking we could have some internal _start that somehow that gets passed a makeItHappen: () -> ...
and that would be the _start(makeItHappen: { () in eventLoop.execute { ... } }
or the DispatchQueue one by default. A bit weird but this way we're staying true to what the method signature promises.
Added some NIO friendly syntactic sugar, based on this comment: swift-server/swift-aws-lambda-runtime#141 (comment)
Is this something we want to follow through?