@@ -22,13 +22,11 @@ import { Memory } from "./memory.js";
2222 * threadChannel: {
2323 * wakeUpMainThread: (unownedJob) => {
2424 * // Send the job to the main thread
25- * postMessage({ type: "job", unownedJob } );
25+ * postMessage(unownedJob);
2626 * },
2727 * listenWakeEventFromMainThread: (listener) => {
2828 * self.onmessage = (event) => {
29- * if (event.data.type === "wake") {
30- * listener();
31- * }
29+ * listener(event.data);
3230 * };
3331 * }
3432 * }
@@ -38,14 +36,12 @@ import { Memory } from "./memory.js";
3836 * const worker = new Worker("worker.js");
3937 * const runtime = new SwiftRuntime({
4038 * threadChannel: {
41- * wakeUpWorkerThread: (tid) => {
42- * worker.postMessage({ type: "wake" } );
39+ * wakeUpWorkerThread: (tid, data ) => {
40+ * worker.postMessage(data );
4341 * },
4442 * listenMainJobFromWorkerThread: (tid, listener) => {
4543 * worker.onmessage = (event) => {
46- * if (event.data.type === "job") {
47- * listener(event.data.unownedJob);
48- * }
44+ listener(event.data);
4945 * };
5046 * }
5147 * }
@@ -65,16 +61,17 @@ export type SwiftRuntimeThreadChannel =
6561 * to the wake event from the main thread sent by `wakeUpWorkerThread`.
6662 * The passed listener function awakes the Web Worker thread.
6763 */
68- listenWakeEventFromMainThread : ( listener : ( ) => void ) => void ;
64+ listenWakeEventFromMainThread : ( listener : ( data : unknown ) => void ) => void ;
6965 }
7066 | {
7167 /**
7268 * This function is expected to be set in the main thread and called
7369 * when the main thread sends a wake event to the Web Worker thread.
7470 * 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.
7572 * The wake event is expected to be listened by `listenWakeEventFromMainThread`.
7673 */
77- wakeUpWorkerThread : ( tid : number ) => void ;
74+ wakeUpWorkerThread : ( tid : number , data : unknown ) => void ;
7875 /**
7976 * This function is expected to be set in the main thread and shuold listen
8077 * to the main job sent by `wakeUpMainThread` from the worker thread.
@@ -607,7 +604,8 @@ export class SwiftRuntime {
607604 swjs_wake_up_worker_thread : ( tid ) => {
608605 const threadChannel = this . options . threadChannel ;
609606 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 , { } ) ;
611609 } else {
612610 throw new Error (
613611 "wakeUpWorkerThread is not set in options given to SwiftRuntime. Please set it to wake up worker threads."
0 commit comments