Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Lx9FNLG2CqeBbVGGd9bFsP
17 lines
460 B
Go
17 lines
460 B
Go
package app
|
|
|
|
import "context"
|
|
|
|
// goStop runs run in the background until Stop, which cancels its context and
|
|
// waits for it to return. Subsystems stop in reverse start order.
|
|
func (a *App) goStop(name string, run func(ctx context.Context)) {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
done := make(chan struct{})
|
|
go func() { defer close(done); run(ctx) }()
|
|
a.onStop(name, func(context.Context) error {
|
|
cancel()
|
|
<-done
|
|
return nil
|
|
})
|
|
}
|