From f4124c62bec92cd5ec0118ed8640cf268b4bf4aa Mon Sep 17 00:00:00 2001 From: Onur Cinar Date: Thu, 5 Sep 2024 19:23:25 -0700 Subject: [PATCH] Fixing a deadlock issue in the outcome calculation. --- helper/skip.go | 5 ++++- strategy/strategy.go | 11 +++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/helper/skip.go b/helper/skip.go index 69dcbd5..bec5f90 100644 --- a/helper/skip.go +++ b/helper/skip.go @@ -17,7 +17,10 @@ func Skip[T any](c <-chan T, count int) <-chan T { go func() { for i := 0; i < count; i++ { - <-c + _, ok := <-c + if !ok { + break + } } Pipe(c, result) diff --git a/strategy/strategy.go b/strategy/strategy.go index cb26887..d4257b5 100644 --- a/strategy/strategy.go +++ b/strategy/strategy.go @@ -43,16 +43,11 @@ func ComputeWithOutcome(s Strategy, c <-chan *asset.Snapshot) (<-chan Action, <- snapshots := helper.Duplicate(c, 2) actions := helper.Duplicate(s.Compute(snapshots[0]), 2) + closings := asset.SnapshotsAsClosings(snapshots[1]) - openings := helper.Skip(asset.SnapshotsAsOpenings(snapshots[1]), 1) + outcomes := Outcome(closings, actions[1]) - outcomes := helper.Echo( - Outcome(openings, actions[0]), - 1, - 1, - ) - - return actions[1], outcomes + return actions[0], outcomes } // AllStrategies returns a slice containing references to all available base strategies.