Skip to content

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

Merged
merged 1 commit into from
Sep 1, 2020
Merged

Add some NIO sugar to ServiceLifecycle.start() #72

merged 1 commit into from
Sep 1, 2020

Conversation

fabianfett
Copy link
Member

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?

@tomerd tomerd merged commit 8f61d72 into swift-server:main Sep 1, 2020
@tomerd
Copy link
Contributor

tomerd commented Sep 1, 2020

thanks @fabianfett <3

Copy link
Contributor

@ktoso ktoso left a 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.
Copy link
Contributor

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> {
Copy link
Contributor

@ktoso ktoso Sep 1, 2020

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?

@fabianfett

Copy link
Contributor

@tomerd tomerd Sep 3, 2020

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?

Copy link
Contributor

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.

@tomerd tomerd added this to the 1.0.0-alpha5 milestone Sep 28, 2020
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 this pull request may close these issues.

3 participants