Skip to content

Commit 09ca95a

Browse files
author
Mat Ryer
committed
added comments
1 parent b2af013 commit 09ca95a

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

start/start.go

+11
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,14 @@ func MustAll(stopGrace time.Duration, startStoppers ...StartStopper) map[StartSt
7070
}
7171
return errs
7272
}
73+
74+
// StopAll stops all StartStopper types and returns another channel
75+
// which will close once all things have finished stopping.
76+
// For more information, see stop.All.
77+
func StopAll(stopGrace time.Duration, startStoppers ...StartStopper) <-chan stop.Signal {
78+
stoppers := make([]stop.Stopper, len(startStoppers))
79+
for i, ss := range startStoppers {
80+
stoppers[i] = ss.(stop.Stopper)
81+
}
82+
return stop.All(stopGrace, stoppers...)
83+
}

start/start_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,19 @@ func TestMustAll(t *testing.T) {
9393
require.False(t, s3.running)
9494

9595
}
96+
97+
func TestStopAll(t *testing.T) {
98+
99+
s1 := &TestStarter{}
100+
s2 := &TestStarter{}
101+
s3 := &ErrorStarter{}
102+
103+
start.All(s1, s2, s3)
104+
105+
<-start.StopAll(1*time.Second, s1, s2, s3)
106+
107+
require.False(t, s1.running)
108+
require.False(t, s2.running)
109+
require.False(t, s3.running)
110+
111+
}

0 commit comments

Comments
 (0)