summaryrefslogtreecommitdiff
path: root/pkg/backend/gatewaychecker.go
blob: e92955953c4934cfaae51f68073477cad1495c95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package backend

import (
	"time"
)

// The gateway selector gets populated asynchronously, so this spawns a goroutine that
// checks whether they've been fetched to update status.
func (c connectionCtx) delayCheckForGateways() {
	go func() {
		cnt := 0
		for {
			if cnt > 60*2 {
				break
			}
			cnt += 1
			time.Sleep(time.Second * 5)
			transport := c.bm.GetTransport()
			locs := c.bm.ListLocationFullness(transport)
			if len(locs) != 0 {
				c.Locations = locs
				updateStatusForGateways()
				break
			}
		}
	}()
}

func updateStatusForGateways() {
	statusMutex.Lock()
	defer statusMutex.Unlock()
	go trigger(OnStatusChanged)
}