From ac06985604e2def6e1414113fd3266243b944303 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 22 Feb 2022 14:17:10 +0100 Subject: util.async: Optionally allow too many 'done' callbacks Sometimes, like in mod_c2s and mod_s2s during shutdown, all you want is to wait for the first done() and not complicate things. --- util/async.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'util/async.lua') diff --git a/util/async.lua b/util/async.lua index ece589cb..2830238f 100644 --- a/util/async.lua +++ b/util/async.lua @@ -73,7 +73,7 @@ local function runner_continue(thread) return true; end -local function waiter(num) +local function waiter(num, allow_many) local thread = checkthread(); num = num or 1; local waiting; @@ -85,7 +85,7 @@ local function waiter(num) num = num - 1; if num == 0 and waiting then runner_continue(thread); - elseif num < 0 then + elseif not allow_many and num < 0 then error("done() called too many times"); end end; -- cgit v1.2.3