From ce19bcd3644fdda8110cbbbf33af3500979fc5a7 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 14 May 2021 12:37:44 +0200 Subject: [PATCH] :sparkles: Minor improvements on batching channel impl. --- backend/src/app/util/async.clj | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/backend/src/app/util/async.clj b/backend/src/app/util/async.clj index a0492e086..984cbb167 100644 --- a/backend/src/app/util/async.clj +++ b/backend/src/app/util/async.clj @@ -81,7 +81,11 @@ (recur (a/timeout max-batch-age) init))) (nil? val) - (a/close! out) + (if (empty? buf) + (a/close! out) + (do + (a/offer! out [:timeout buf]) + (a/close! out))) (identical? port in) (let [buf (conj buf val)] @@ -91,3 +95,7 @@ (recur (a/timeout max-batch-age) init)) (recur tch buf)))))) out)) + +(defn thread-sleep + [ms] + (Thread/sleep ms))