diff options
author | kali kaneko (leap communications) <kali@leap.se> | 2021-06-22 17:57:29 +0200 |
---|---|---|
committer | kali kaneko (leap communications) <kali@leap.se> | 2021-06-22 18:04:48 +0200 |
commit | 9f1807c2c053e3b57881d42ebf58ec26dfee1b1d (patch) | |
tree | 70abd66546c6ad1f49edfc032eaf9f1cd8ca5d30 /pkg/backend/gatewaychecker.go | |
parent | 514a6a8a1f1188a8dd95c79db150711cdc30bc48 (diff) |
[bug] populate gateways early on
- Closes: #511
Diffstat (limited to 'pkg/backend/gatewaychecker.go')
-rw-r--r-- | pkg/backend/gatewaychecker.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/pkg/backend/gatewaychecker.go b/pkg/backend/gatewaychecker.go new file mode 100644 index 0000000..f10e47e --- /dev/null +++ b/pkg/backend/gatewaychecker.go @@ -0,0 +1,32 @@ +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 + } + 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) +} |