moonzero · control plane v0.15.0 · 49 packages · 4 targets · Apache-2.0 docs / data / services GitHub

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.

struct Service

structOne 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) -> Service

fnA named service.

struct ServiceGroup

structSeveral 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() -> ServiceGroup

fnA group with nothing in it.

fn ServiceGroup::add(self : ServiceGroup, service : Service) -> Unit

fnAdd a service to the group.

fn ServiceGroup::add_fn( self : ServiceGroup, name : String, start : async () -> Unit) -> Unit

fnAdd 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) -> Unit

itemRun 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.