From ac982abdf4de3390ccc68044f993faff35359d97 Mon Sep 17 00:00:00 2001 From: "Tobias S. Josefowitz" <tobij@tobij.de> Date: Tue, 20 Oct 2020 20:07:21 +0200 Subject: [PATCH] Concurrent: Catch executor throwing and convert to rejection There is arguably little reason to use the executor 'API' if not for it doing this. --- lib/modules/Concurrent.pmod | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/modules/Concurrent.pmod b/lib/modules/Concurrent.pmod index bf85516928..1600837628 100644 --- a/lib/modules/Concurrent.pmod +++ b/lib/modules/Concurrent.pmod @@ -906,8 +906,20 @@ class Promise function(mixed:void), mixed ...:void) executor, mixed ... extra) { state = STATE_NO_FUTURE; - if (executor) - executor(success, failure, @extra); + + if (executor) { + mixed err = catch(executor(success, failure, @extra)); + + // This unfortunately does hide the real error in case of + // double-finalization, i.e. + // fail("I reject!"); + // error("I rejected.\n"); + // in the executor will leave our caller with an error about the + // Promise already having been finalized, not giving anyone too much + // information about where the double-finalization occured... + if (err) + failure(err); + } } Future on_success(function(mixed, mixed ... : void) cb, mixed ... extra) -- GitLab