mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-03 15:17:25 +00:00
lib/svcutil: Simplify doneService (#7303)
OnSupervisorDone no longer allocates. Co-authored-by: greatroar <@>
This commit is contained in:
parent
e32a516b5f
commit
6c3e187d1d
@ -144,19 +144,17 @@ func (s *service) String() string {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type doneService struct {
|
type doneService func()
|
||||||
fn func()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *doneService) Serve(ctx context.Context) error {
|
func (fn doneService) Serve(ctx context.Context) error {
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
s.fn()
|
fn()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnSupervisorDone calls fn when sup is done.
|
// OnSupervisorDone calls fn when sup is done.
|
||||||
func OnSupervisorDone(sup *suture.Supervisor, fn func()) {
|
func OnSupervisorDone(sup *suture.Supervisor, fn func()) {
|
||||||
sup.Add(&doneService{fn})
|
sup.Add(doneService(fn))
|
||||||
}
|
}
|
||||||
|
|
||||||
func SpecWithDebugLogger(l logger.Logger) suture.Spec {
|
func SpecWithDebugLogger(l logger.Logger) suture.Spec {
|
||||||
|
Loading…
Reference in New Issue
Block a user