From 69c85d74e0e1d5d75133d950e7fb236db4e9d642 Mon Sep 17 00:00:00 2001 From: Michael Van Canneyt Date: Mon, 2 Dec 2024 21:28:10 +0100 Subject: [PATCH] * Allow to work in worker --- packages/wasm-utils/src/wasm.pas2js.timer.pas | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/wasm-utils/src/wasm.pas2js.timer.pas b/packages/wasm-utils/src/wasm.pas2js.timer.pas index ebd74a5..745ec2d 100644 --- a/packages/wasm-utils/src/wasm.pas2js.timer.pas +++ b/packages/wasm-utils/src/wasm.pas2js.timer.pas @@ -8,7 +8,13 @@ unit wasm.pas2js.timer; interface uses - sysutils, js, wasienv, web, wasm.timer.shared; + sysutils, js, wasienv, + {$ifdef JOB_WORKER} + webworker, + {$ELSE} + web, + {$ENDIF} + wasm.timer.shared; Type TWasmPointer = longint; @@ -33,6 +39,7 @@ Type implementation + { TWasmTimerAPI } procedure TWasmTimerAPI.LogCall(const Msg: String); @@ -102,7 +109,11 @@ begin Callback:=InstanceExports['__wasm_timer_tick']; if Not Assigned(Callback) then Exit(0); + {$IFDEF JOB_WORKER} + aTimerID:=self_.setInterval(@HandleTimer,aInterval); + {$ELSE} aTimerID:=Window.setInterval(@HandleTimer,aInterval); + {$ENDIF} Result:=aTimerID; {$IFNDEF NOLOGAPICALLS} If LogAPICalls then @@ -114,7 +125,11 @@ procedure TWasmTimerApi.DeallocateTimer(timerid: TWasmTimerID); begin If LogAPICalls then LogCall('DeAllocateTimer(%d)',[TimerID]); + {$IFDEF JOB_WORKER} + self_.clearInterval(TimerID); + {$else} window.clearInterval(TimerID); + {$endif} end;