Properly exit workers, plus small fixes.

This commit is contained in:
Joseph Cloutier
2022-03-01 14:43:42 -05:00
parent ec4d0b7ee9
commit 5f04b3e613
3 changed files with 12 additions and 3 deletions

View File

@@ -55,8 +55,8 @@ class HTML5Thread {
try
{
job.dispatch();
Lib.global.onmessage = __current.dispatchMessage;
job.dispatch();
}
catch (e:Dynamic)
{
@@ -317,7 +317,6 @@ abstract WorkFunction<T:haxe.Constraints.Function>(WorkFunctionData<T>) from Wor
{
if (Context.defined("lime-warn-portability"))
{
trace(qualifiedFunc);
Context.warning("Value doesn't appear to be a static function.", func.pos);
}
return defaultOutput;
@@ -602,6 +601,6 @@ class Lib
// specification only uses the former.
@:forward
abstract Transferable(Dynamic) #if macro from Dynamic
#else from js.lib.ArrayBuffer from js.html.MessagePort from js.html.ImageBitmap #end
#else from lime.utils.ArrayBuffer from js.html.MessagePort from js.html.ImageBitmap #end
{
}

View File

@@ -36,6 +36,8 @@ abstract BackgroundWorker(ThreadPool)
@:deprecated("Instead pass the callback to BackgroundWorker.run().")
@:noCompletion @:dox(hide) public var doWork(get, never):{ add: (Dynamic->Void) -> Void };
public var eventSource(get, never):Dynamic;
/**
__Call this only from the main thread.__
@@ -127,6 +129,11 @@ abstract BackgroundWorker(ThreadPool)
// Getters & Setters
private inline function get_eventSource():Dynamic
{
return this.eventSource != null ? this.eventSource.state : null;
}
private function get_doWork()
{
return {

View File

@@ -330,6 +330,9 @@ class ThreadPool extends WorkOutput
if (job.event == EXIT)
{
#if html5
Thread.current().destroy();
#end
return;
}