Improve ThreadPool job chaining.

This commit is contained in:
Joseph Cloutier
2022-02-09 15:28:13 -05:00
parent c6f355941b
commit f3c35a2fd0

View File

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