@@ -22,13 +22,11 @@ import { Memory } from "./memory.js";
22
22
* threadChannel: {
23
23
* wakeUpMainThread: (unownedJob) => {
24
24
* // Send the job to the main thread
25
- * postMessage({ type: "job", unownedJob } );
25
+ * postMessage(unownedJob);
26
26
* },
27
27
* listenWakeEventFromMainThread: (listener) => {
28
28
* self.onmessage = (event) => {
29
- * if (event.data.type === "wake") {
30
- * listener();
31
- * }
29
+ * listener(event.data);
32
30
* };
33
31
* }
34
32
* }
@@ -38,14 +36,12 @@ import { Memory } from "./memory.js";
38
36
* const worker = new Worker("worker.js");
39
37
* const runtime = new SwiftRuntime({
40
38
* threadChannel: {
41
- * wakeUpWorkerThread: (tid) => {
42
- * worker.postMessage({ type: "wake" } );
39
+ * wakeUpWorkerThread: (tid, data ) => {
40
+ * worker.postMessage(data );
43
41
* },
44
42
* listenMainJobFromWorkerThread: (tid, listener) => {
45
43
* worker.onmessage = (event) => {
46
- * if (event.data.type === "job") {
47
- * listener(event.data.unownedJob);
48
- * }
44
+ listener(event.data);
49
45
* };
50
46
* }
51
47
* }
@@ -65,16 +61,17 @@ export type SwiftRuntimeThreadChannel =
65
61
* to the wake event from the main thread sent by `wakeUpWorkerThread`.
66
62
* The passed listener function awakes the Web Worker thread.
67
63
*/
68
- listenWakeEventFromMainThread : ( listener : ( ) => void ) => void ;
64
+ listenWakeEventFromMainThread : ( listener : ( data : unknown ) => void ) => void ;
69
65
}
70
66
| {
71
67
/**
72
68
* This function is expected to be set in the main thread and called
73
69
* when the main thread sends a wake event to the Web Worker thread.
74
70
* The `tid` is the thread ID of the worker thread to be woken up.
71
+ * The `data` is the data to be sent to the worker thread.
75
72
* The wake event is expected to be listened by `listenWakeEventFromMainThread`.
76
73
*/
77
- wakeUpWorkerThread : ( tid : number ) => void ;
74
+ wakeUpWorkerThread : ( tid : number , data : unknown ) => void ;
78
75
/**
79
76
* This function is expected to be set in the main thread and shuold listen
80
77
* to the main job sent by `wakeUpMainThread` from the worker thread.
@@ -607,7 +604,8 @@ export class SwiftRuntime {
607
604
swjs_wake_up_worker_thread : ( tid ) => {
608
605
const threadChannel = this . options . threadChannel ;
609
606
if ( threadChannel && "wakeUpWorkerThread" in threadChannel ) {
610
- threadChannel . wakeUpWorkerThread ( tid ) ;
607
+ // Currently, the data is not used, but it can be used in the future.
608
+ threadChannel . wakeUpWorkerThread ( tid , { } ) ;
611
609
} else {
612
610
throw new Error (
613
611
"wakeUpWorkerThread is not set in options given to SwiftRuntime. Please set it to wake up worker threads."
0 commit comments