From f41bf220df42c398cf67e36e33fc85c4973247a6 Mon Sep 17 00:00:00 2001 From: LeonardGiglhuber Date: Mon, 3 Oct 2022 12:55:47 +0200 Subject: [PATCH] Remove cancelled pushes and shifts at the end of every processOrders() call; --- lib/index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/index.js b/lib/index.js index 4917e19..0a5d788 100644 --- a/lib/index.js +++ b/lib/index.js @@ -104,6 +104,20 @@ const Channel = function(length = 0) { pushes.splice(0, index.push); shifts.splice(0, index.shift); + + // Remove cancelled pushes + for (let i = pushes.length - 1; i >= 0; i--) { + if (pushes[i].cancelled) { + pushes.splice(i, 1); + } + } + + // Remove cancelled shifts + for (let i = shifts.length - 1; i >= 0; i--) { + if (shifts[i].cancelled) { + shifts.splice(i, 1); + } + } }; const readOnly = Object.freeze(