package context import ( "sync" "git.sr.ht/~cco/go-scopes/lib" ) type appContext struct { *context services Services waitgroup *sync.WaitGroup doneCh chan struct{} } func (ctx *appContext) ChildContext(cfg lib.Config) Context { cctx := makeCtx(cfg, ctx) ctx.services[cfg.Name()] = cctx ctx.children = append(ctx.children, cctx) return cctx } func (ctx *appContext) Services() Services { return ctx.services } func (ctx *appContext) WithState(state ContextState) Context { ctx.state = state return ctx } func (ctx *appContext) WaitGroup() *sync.WaitGroup { return ctx.waitgroup } func (ctx *appContext) Done() <-chan struct{} { return ctx.doneCh } func (ctx *appContext) Stop() { close(ctx.doneCh) } func AppContext(cfg lib.Config) Context { ctx := &appContext{ context: makeCtx(cfg, nil), services: Services{}, waitgroup: &sync.WaitGroup{}, doneCh: make(chan struct{}), } ctx.services[cfg.Name()] = ctx return ctx }