-
Notifications
You must be signed in to change notification settings - Fork 41
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
Conversation
Sources/Lifecycle/Lifecycle.swift
Outdated
|
||
public protocol LifecycleRegistrar { |
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.
not in love with this name, better ideas?
@fabianfett as discussed for the lambda use case |
Sources/Lifecycle/Lifecycle.swift
Outdated
self.register(label: label, start: .none, shutdown: handler) | ||
} | ||
} | ||
|
||
internal struct LifecycleTaskImpl: LifecycleTask { |
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.
Is it more common to name these LifecycleTask: LifecycleTaskProtocol
? *Impl
is kind of Java-y.
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.
@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?
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.
It's not too bad if it's internal; true that making the actual public name good is more important 👍
@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? |
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
1ec779c
to
68facea
Compare
renamed wdyt? |
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.
Typo in type name, otherwise 👍
Sources/Lifecycle/Lifecycle.swift
Outdated
/// - parameters: | ||
/// - tasks: array of `LifecycleTask`. | ||
func register(_ tasks: [LifecycleTask]) { | ||
extension ServiceLifecycle: LifecycleTasksConainer { |
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.
extension ServiceLifecycle: LifecycleTasksConainer { | |
extension ServiceLifecycle: LifecycleTaskContainer { |
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.
LifecycleTaskContainer sounds good :)
Sources/Lifecycle/Lifecycle.swift
Outdated
|
||
func start(_ callback: @escaping (Error?) -> Void) { | ||
self.start.run(callback) | ||
extension ComponentLifecycle: LifecycleTasksConainer { |
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.
extension ComponentLifecycle: LifecycleTasksConainer { | |
extension ComponentLifecycle: LifecycleTaskContainer { |
Sources/Lifecycle/Lifecycle.swift
Outdated
|
||
extension LifecycleTasksConainer { |
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.
extension LifecycleTasksConainer { | |
extension LifecycleTaskContainer { |
sounds good 👍 |
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