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: } }