From 9f1807c2c053e3b57881d42ebf58ec26dfee1b1d Mon Sep 17 00:00:00 2001 From: "kali kaneko (leap communications)" Date: Tue, 22 Jun 2021 17:57:29 +0200 Subject: [bug] populate gateways early on - Closes: #511 --- pkg/backend/gatewaychecker.go | 32 ++++++++++++++++++++++++++++++++ pkg/backend/init.go | 1 + 2 files changed, 33 insertions(+) create mode 100644 pkg/backend/gatewaychecker.go (limited to 'pkg/backend') 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) +} diff --git a/pkg/backend/init.go b/pkg/backend/init.go index 6fb794a..b7469c1 100644 --- a/pkg/backend/init.go +++ b/pkg/backend/init.go @@ -35,6 +35,7 @@ func initializeContext(opts *InitOpts) { go checkErrors(errCh) initializeBitmask(errCh, opts) go trigger(OnStatusChanged) + ctx.delayCheckForGateways() } func checkErrors(errCh chan string) { -- cgit v1.2.3