Return []error from Stop() channel, allow recursive stop groups

This commit is contained in:
Justin Li
2018-09-09 11:14:24 -04:00
parent 21f500c93e
commit d95120c817
9 changed files with 76 additions and 57 deletions
+4 -4
View File
@@ -144,19 +144,19 @@ func (h *hook) updateKeys() error {
return nil
}
func (h *hook) Stop() <-chan error {
func (h *hook) Stop() stop.Result {
log.Debug("attempting to shutdown JWT middleware")
select {
case <-h.closing:
return stop.AlreadyStopped
default:
}
c := make(chan error)
c := make(stop.Channel)
go func() {
close(h.closing)
close(c)
c.Done()
}()
return c
return c.Result()
}
func (h *hook) HandleAnnounce(ctx context.Context, req *bittorrent.AnnounceRequest, resp *bittorrent.AnnounceResponse) (context.Context, error) {
+1 -1
View File
@@ -105,7 +105,7 @@ func (l *Logic) AfterScrape(ctx context.Context, req *bittorrent.ScrapeRequest,
// Stop stops the Logic.
//
// This stops any hooks that implement stop.Stopper.
func (l *Logic) Stop() []error {
func (l *Logic) Stop() stop.Result {
stopGroup := stop.NewGroup()
for _, hook := range l.preHooks {
stoppable, ok := hook.(stop.Stopper)