From 6baa15ba14665380d226750be913b7c7db9bbcbf Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 7 Aug 2020 15:30:05 +0200 Subject: [PATCH] Make user.stop block This allows callers to wait until the user has been stopped. --- user.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/user.go b/user.go index 6cfe8c5..c9c3fb8 100644 --- a/user.go +++ b/user.go @@ -219,6 +219,7 @@ type user struct { srv *Server events chan event + done chan struct{} networks []*network downstreamConns []*downstreamConn @@ -238,6 +239,7 @@ func newUser(srv *Server, record *User) *user { User: *record, srv: srv, events: make(chan event, 64), + done: make(chan struct{}), } } @@ -284,6 +286,8 @@ func (u *user) getNetworkByID(id int64) *network { } func (u *user) run() { + defer close(u.done) + networks, err := u.srv.db.ListNetworks(u.Username) if err != nil { u.srv.Logger.Printf("failed to list networks for user %q: %v", u.Username, err) @@ -563,4 +567,5 @@ func (u *user) updatePassword(hashed string) error { func (u *user) stop() { u.events <- eventStop{} + <-u.done }