swift-service-lifecycle
swift-service-lifecycle copied to clipboard
Future idea: if @main lands and SPM supports it, offer an "entry point"?
The ongoing pitch https://forums.swift.org/t/main-type-based-program-execution/34624 introduces @main
define-able entry points.
It is also aimed for libraries to provide their patterns / entry points.
It currently will NOT work with Swift Package Manager... but if we were able to make it work there, we could offer APIs similar to
@main
struct MyService: ServiceLifecycleMain {
// or struct MyService: ServiceBootstrapMain {
// some command line things, using ParsableCommand
@Argument(help: "What port to bind to")
var port: [Int]
// NOT ACTUAL API; not through through how it'd look like exactly,
// but we'd allow registering the phases here?
func configurePhases/Tasks() {}
func onShutdown(error: [String: Error]?) {}
}
thats a good idea once the feature is available to us 👍
@ktoso & @tomerd This seems like a great idea which should now be possible through .executableTarget
(5.4) 👍 I like the interplay of ArgumentParser
and Lifecycle
. Though getting this example to work would require Lifecycle
to depend on ArgumentParser
. Is that something we'd be open to doing?
I think this could be good, but as a separate, optional target, kind of like how we do lifecycle + nio
we could/should probably also just provide a static main that calls start etc that folks can use in @main setups
separate target sounds good :)
Sounds good 👍 I'll poke around a bit.
This can be closed given the upcoming 2.0 revision which handles much more :)