-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathGeometrizeWorkerInterface.hx
49 lines (39 loc) · 1.14 KB
/
GeometrizeWorkerInterface.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package;
#if geometrize_frontend
import js.html.Worker;
import GeometrizeWorkerMessages;
/**
* Wrapper class for handling and communicating with a web worker that runs the Geometrize worker script.
* @author Sam Twidale (https://www.geometrize.co.uk/)
*/
class GeometrizeWorkerInterface {
private var worker:Worker;
/**
* Creates a new web worker that runs the Geometrize worker script.
*/
public function new() {
worker = new Worker(GeometrizeWorker.scriptPath);
worker.onmessage = function(message:Dynamic) {
onMessage(message.data);
}
}
/**
* Posts a message to the Geometrize web worker.
* @param message The message to post to the web worker.
*/
public function postMessage(message:FrontendToWorkerMessage):Void {
worker.postMessage(message);
}
/**
* Terminates the web worker.
*/
public function terminate():Void {
worker.terminate();
}
/**
* Called when a message is received from the web worker - rebind this method to provide your own handler method.
* @param message The message received from the web worker.
*/
dynamic public function onMessage(message:WorkerToFrontendMessage):Void {}
}
#end