Skip to content

abstract registration function into a protocol #75

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 3 commits into from
Sep 26, 2020

Conversation

tomerd
Copy link
Contributor

@tomerd tomerd commented Sep 18, 2020

motivation: allow libraries that want to expose the lifecycle so that downstream code could register additional items to do so regardless of the lifecycle backend

changes: abstract registration function into a protocol and conform ComponentLifecycle and ServiceLifecycle to it


public protocol LifecycleRegistrar {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not in love with this name, better ideas?

@tomerd
Copy link
Contributor Author

tomerd commented Sep 18, 2020

@fabianfett as discussed for the lambda use case

self.register(label: label, start: .none, shutdown: handler)
}
}

internal struct LifecycleTaskImpl: LifecycleTask {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it more common to name these LifecycleTask: LifecycleTaskProtocol? *Impl is kind of Java-y.

Copy link
Contributor Author

@tomerd tomerd Sep 21, 2020

Choose a reason for hiding this comment

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

@yim-lee LifecycleTask is the public "currency type", while LifecycleTaskImpl is internal. While there are a few examples where Swift stdlib uses the XxxProtocol convention (e.g. StringProtocol) its actually not all that common to use it for public "currency type". That said I too not in love with LifecycleTaskImpl but since its internal I let it slide. wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not too bad if it's internal; true that making the actual public name good is more important 👍

@fabianfett
Copy link
Member

@tomerd Since we originally intended this change for Lambda, I think we should first find a solution to this: swift-server/swift-aws-lambda-runtime#141 (comment)

Or do you want this change no matter what Lambda does?

@tomerd
Copy link
Contributor Author

tomerd commented Sep 24, 2020

Or do you want this change no matter what Lambda does?

I think this is a good change in any case so I would merge this

motivation: allow libraries that want to expose the lifecycle so that downstream code could register additional items to do so regardless of the lifecycle backend

changes: abstract registration function into a protocol and conform ComponentLifecycle and ServiceLifecycle to it
@tomerd
Copy link
Contributor Author

tomerd commented Sep 26, 2020

@yim-lee @fabianfett @ktoso

renamed LifecycleRegistrar -> LifecycleTasksContainer and LifecycleTaskImpl -> _ LifecycleTask

wdyt?

Copy link
Collaborator

@yim-lee yim-lee left a comment

Choose a reason for hiding this comment

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

Typo in type name, otherwise 👍

/// - parameters:
/// - tasks: array of `LifecycleTask`.
func register(_ tasks: [LifecycleTask]) {
extension ServiceLifecycle: LifecycleTasksConainer {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
extension ServiceLifecycle: LifecycleTasksConainer {
extension ServiceLifecycle: LifecycleTaskContainer {

Copy link
Contributor

Choose a reason for hiding this comment

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

LifecycleTaskContainer sounds good :)


func start(_ callback: @escaping (Error?) -> Void) {
self.start.run(callback)
extension ComponentLifecycle: LifecycleTasksConainer {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
extension ComponentLifecycle: LifecycleTasksConainer {
extension ComponentLifecycle: LifecycleTaskContainer {


extension LifecycleTasksConainer {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
extension LifecycleTasksConainer {
extension LifecycleTaskContainer {

@ktoso
Copy link
Contributor

ktoso commented Sep 26, 2020

sounds good 👍

@tomerd tomerd merged commit 3a02d48 into swift-server:main Sep 26, 2020
@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.

4 participants