From bd5d4c99ae21df815dae1435347ad402150cc9c1 Mon Sep 17 00:00:00 2001 From: Scott Date: Fri, 7 Jun 2024 14:10:12 +1000 Subject: [PATCH] utilises concurrent error grabber --- exchanges/deribit/deribit_wrapper.go | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/exchanges/deribit/deribit_wrapper.go b/exchanges/deribit/deribit_wrapper.go index 8abdbd56395..15c8b567274 100644 --- a/exchanges/deribit/deribit_wrapper.go +++ b/exchanges/deribit/deribit_wrapper.go @@ -8,7 +8,6 @@ import ( "sort" "strconv" "strings" - "sync" "time" "github.com/shopspring/decimal" @@ -256,31 +255,23 @@ func (d *Deribit) FetchTradablePairs(ctx context.Context, assetType asset.Item) // them in the exchanges config func (d *Deribit) UpdateTradablePairs(ctx context.Context, forceUpdate bool) error { assets := d.GetAssetTypes(false) - var wg sync.WaitGroup - wg.Add(len(assets)) - errC := make(chan error, len(assets)) + errs := common.CollectErrors(len(assets)) for x := range assets { go func(x int) { - defer wg.Done() + defer errs.Wg.Done() pairs, err := d.FetchTradablePairs(ctx, assets[x]) if err != nil { - errC <- err + errs.C <- err return } err = d.UpdatePairs(pairs, assets[x], false, forceUpdate) if err != nil { - errC <- err + errs.C <- err return } }(x) } - wg.Wait() - close(errC) - var errs error - for err := range errC { - errs = common.AppendError(errs, err) - } - return errs + return errs.Collect() } // UpdateTickers updates the ticker for all currency pairs of a given asset type