mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-04-05 11:17:45 +02:00
* Allow to work in worker
This commit is contained in:
parent
a6f4d0f1ce
commit
69c85d74e0
@ -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;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user