From f3c35a2fd0ef837c689a53f1419e7546427dc12c Mon Sep 17 00:00:00 2001 From: Joseph Cloutier Date: Wed, 9 Feb 2022 15:28:13 -0500 Subject: [PATCH] Improve `ThreadPool` job chaining. --- src/lime/system/ThreadPool.hx | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/lime/system/ThreadPool.hx b/src/lime/system/ThreadPool.hx index f6c40e249..539d80379 100644 --- a/src/lime/system/ThreadPool.hx +++ b/src/lime/system/ThreadPool.hx @@ -313,6 +313,17 @@ class ThreadPool extends BackgroundWorker case COMPLETE, ERROR: activeThreads--; + // Call `onComplete` before closing threads, in case the + // listener queues a new job. + if (threadEvent.event == COMPLETE) + { + onComplete.dispatch(threadEvent.state); + } + else + { + onError.dispatch(threadEvent.state); + } + #if (!force_synchronous && (target.threaded || cpp || neko)) if (mode == MULTI_THREADED && ((__numPendingJobs > idleThreads && currentThreads > minThreads) @@ -323,15 +334,6 @@ class ThreadPool extends BackgroundWorker } #end - if (threadEvent.event == COMPLETE) - { - onComplete.dispatch(threadEvent.state); - } - else - { - onError.dispatch(threadEvent.state); - } - default: } }