You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Stoppable is a function that can be stopped with the method Stop. You can also listen on the Stopped channel to see when it has been stopped.
64
+
// Stoppable is different from a context cancelation because it waits until the function has cleaned up before broadcasting on the Stopped channel
65
+
typeStoppablestruct {
66
+
Stoppedchanstruct{}
67
+
stopchanstruct{}
68
+
once sync.Once
69
+
}
70
+
71
+
// Stop signals the provided function that it needs to stop
72
+
func (s*Stoppable) Stop() {
73
+
s.once.Do(func() {
74
+
close(s.stop)
75
+
})
76
+
}
77
+
78
+
// Run creates a new stoppable function from the provided func. When you call the Stop method on the returned Stoppable the stop channel fed to the provided func is closed,
79
+
// signaling the need to stop. When the provided func returns the Stopped channel on the
80
+
// returned Stoppable is closed as well, broadcasting the message that it has finished
0 commit comments