09 / DATA
services
A group whose members share one lifetime: every service is a task that runs until it returns or is cancelled, so a failure cancels the rest instead of leaving half a process running.
WHERE IT SITS
INTERFACE
struct ServicestructOne service in a group: a name, so a failure can say which one it was, and the body that runs it until it is cancelled.
fn Service::new(name : String, start : async () -> Unit) -> ServicefnA named service.
struct ServiceGroupstructSeveral services run as one process. Every service is a task that runs until it returns or is cancelled, so a server loop and a background refresher share one lifetime: when the first fails, the rest are cancelled and the failure reaches the caller rather than leaving half a process running.
fn ServiceGroup::new() -> ServiceGroupfnA group with nothing in it.
fn ServiceGroup::add(self : ServiceGroup, service : Service) -> UnitfnAdd a service to the group.
fn ServiceGroup::add_fn( self : ServiceGroup, name : String, start : async () -> Unit) -> UnitfnAdd a service under name.
fn ServiceGroup::names(self : ServiceGroup) -> Array[String]fnThe names of the services in the group, in the order they were added.
async fn ServiceGroup::start(self : ServiceGroup) -> UnititemRun every service concurrently and return when all of them have finished. A service that fails cancels the others, so a group either runs or reports what stopped it — it never leaves a member behind.