wgengine/monitor: change API to permit multiple independent callbakcks

Currently it assumes exactly 1 registered callback. This changes it to
support 0, 1, or more than 1.

This is a step towards plumbing wgengine/monitor into more places (and
moving some of wgengine's interface state fetching into monitor in a
later step)

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2021-02-27 19:33:21 -08:00
parent 0eea490724
commit dda03a911e
3 changed files with 41 additions and 14 deletions

View File

@@ -69,13 +69,14 @@ func runMonitor(ctx context.Context) error {
j, _ := json.MarshalIndent(st, "", " ")
os.Stderr.Write(j)
}
mon, err := monitor.New(log.Printf, func() {
log.Printf("Link monitor fired. State:")
dump()
})
mon, err := monitor.New(log.Printf)
if err != nil {
return err
}
mon.RegisterChangeCallback(func() {
log.Printf("Link monitor fired. State:")
dump()
})
log.Printf("Starting link change monitor; initial state:")
dump()
mon.Start()