Browse Source

* Allow to transfer objects

Michael Van Canneyt 4 months ago
parent
commit
86c80c1198
1 changed files with 16 additions and 0 deletions
  1. 16 0
      packages/rtl/src/Rtl.WorkerCommands.pas

+ 16 - 0
packages/rtl/src/Rtl.WorkerCommands.pas

@@ -115,6 +115,8 @@ Type
     // Send command to thread that started this worker. Cannot be used in main thread
     procedure SendCommand(aCommand : TCustomWorkerCommand); virtual;
     // Send command to thread that started this worker. Cannot be used in main thread
+    procedure SendCommand(aCommand : TCustomWorkerCommand; aTransfer : Array of JSValue); virtual;
+    // Send command to thread that started this worker. Cannot be used in main thread
     procedure SendConsoleCommand(aCommand : TConsoleOutputCommand); virtual;
     // Send command to all registered workers
     procedure BroadcastCommand(aCommand : TCustomWorkerCommand);
@@ -319,6 +321,20 @@ begin
   end;
 end;
 
+procedure TCommandDispatcher.SendCommand(aCommand: TCustomWorkerCommand; aTransfer: array of JSValue);
+
+begin
+  if not (isWebWorker or IsServiceWorker) then
+    Raise EWorkerCommand.Create('Cannot send to starting thread from main page');
+  CheckSenderID(aCommand);
+  {$IFDEF DEBUGCOMMANDDISPATCHER}
+  Writeln('Sending message to worker controller: ',TJSJSON.stringify(aCommand));
+  {$ENDIF}
+  asm
+  self.postMessage(aCommand,aTransfer);
+  end;
+end;
+
 procedure TCommandDispatcher.SendConsoleCommand(aCommand: TConsoleOutputCommand);
 
 begin