-
Notifications
You must be signed in to change notification settings - Fork 41
ServiceGroup
should support dynamically adding Services
while its running
#185
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
Comments
I think we can totally do that and be able to add dynamic services to the group. I was briefly thinking if having dependency between services during startup could be used here. I think it could but it would become awkward to spell. So yeah great feature requests! |
I was about to give this a go, but got stuck on a fundamental API question: The inner plumbings are quite straight forward I would say (some async sequence of I was going in with a non-throwing public actor ServiceGroup {
//...
private let
nonisolated private let addedServices: AsyncStream<ServiceGroupConfiguration.ServiceConfiguration>.Continuation
//...
nonisolated public func addService(_ serviceConfiguration: ServiceGroupConfiguration.ServiceConfiguration) {
// Without making `addService` throwing and/or async, there is not a lot we could do with the result of yield
addedServices.yield(serviceConfiguration)
}
And, you'd theoretically have an unbounded buffer of added services if nobody ever calls The alternative is to access actor state in Any thoughts? |
Hi @sliemeobn,
can you say more about why it wouldn't be a friendly API to call? |
I feel like we'd be offloading a bunch of fringe details to the caller of Then again, |
I knew this moment would come to bite me and now it did. I regret making the I agree with your general statement that |
@FranzBusch Now that I am a few LOC in, I am not so sure anymore. Having an /// The internal state of the ``ServiceGroup``.
private enum State {
...
case running(
gracefulShutdownStreamContinuation: AsyncStream<Void>.Continuation,
addedServiceChannel: AsyncChannel<ServiceGroupConfiguration.ServiceConfiguration>
)
....
}
public func addService(_ serviceConfiguration: ServiceGroupConfiguration.ServiceConfiguration) async {
switch self.state {
case var .initial(services: services):
self.state = .initial(services: [])
services.append(serviceConfiguration)
self.state = .initial(services: services)
case .running(_, let addedServiceChannel):
await addedServiceChannel.send(serviceConfiguration)
case .finished:
return //TBD: I think doing nothing is fine, it is not unlike creating a service group and never calling run...
}
} |
I just opened a PR with the least intrusive method I could think of. |
somewhat straight-forward implementation draft of #185 choices were made, what do we think?
Thanks @sliemeobn for the fix in #199 |
There are scenarios in which users need a running Service in order to retrieve data. This data shall then be used to spawn another Service.
An example for this could be querying AWS SSM for a secret that is then used inside a Lambda.
I imagine the code to look something like this:
The text was updated successfully, but these errors were encountered: