diff --git a/lib/gat/pool.go b/lib/gat/pool.go index 243d0f01ad65feafb4e835b63d3c575b5333a704..4b4d662bd465c8392dd68cc6f9a6b4f4632751d2 100644 --- a/lib/gat/pool.go +++ b/lib/gat/pool.go @@ -188,11 +188,28 @@ func (T *Pool) Scale(amount int) { } T.mu.Unlock() - for _, recipe := range recipes { - amount = T.recipes[recipe].Scale(T, amount) - if amount == 0 { - break +outer: + for len(recipes) > 0 { + j := 0 + for i := 0; i < len(recipes); i++ { + recipe := recipes[i] + if amount > 0 { + if T.recipes[recipe].Scale(T, 1) == 0 { + amount-- + recipes[j] = recipes[i] + j++ + } + } else if amount < 0 { + if T.recipes[recipe].Scale(T, -1) == 0 { + amount++ + recipes[j] = recipes[i] + j++ + } + } else { + break outer + } } + recipes = recipes[:j] } }