mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-09-13 22:19:09 +02:00
* Let CommandDispatcher handle console channel
This commit is contained in:
parent
f6d89a5cb6
commit
31b0027881
@ -110,6 +110,8 @@ Type
|
|||||||
procedure SendCommand(const aName : string; aCommand : TCustomWorkerCommand);
|
procedure SendCommand(const aName : string; aCommand : TCustomWorkerCommand);
|
||||||
// Send command to thread that started this worker. Cannot be used in main thread
|
// Send command to thread that started this worker. Cannot be used in main thread
|
||||||
procedure SendCommand(aCommand : TCustomWorkerCommand); virtual;
|
procedure SendCommand(aCommand : TCustomWorkerCommand); 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
|
// Send command to all registered workers
|
||||||
procedure BroadcastCommand(aCommand : TCustomWorkerCommand);
|
procedure BroadcastCommand(aCommand : TCustomWorkerCommand);
|
||||||
// Register a command handler for command aCommand
|
// Register a command handler for command aCommand
|
||||||
@ -121,8 +123,10 @@ Type
|
|||||||
// Remove a worker from broadcast list
|
// Remove a worker from broadcast list
|
||||||
Procedure UnRegisterWorker(aWorker : TJSWorker);
|
Procedure UnRegisterWorker(aWorker : TJSWorker);
|
||||||
Procedure UnRegisterWorker(const aName : string);
|
Procedure UnRegisterWorker(const aName : string);
|
||||||
|
|
||||||
Class function SetDispatcherClass(aClass : TCommandDispatcherClass) : TCommandDispatcherClass;
|
Class function SetDispatcherClass(aClass : TCommandDispatcherClass) : TCommandDispatcherClass;
|
||||||
Class property instance : TCommandDispatcher read GetInstance;
|
Class property instance : TCommandDispatcher read GetInstance;
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CommandDispatcher : TCommandDispatcher;
|
function CommandDispatcher : TCommandDispatcher;
|
||||||
@ -251,8 +255,10 @@ constructor TCommandDispatcher.create;
|
|||||||
begin
|
begin
|
||||||
FMap:=TJSMap.new();
|
FMap:=TJSMap.new();
|
||||||
FConsoleChannel:=TJSBroadcastChannel.new(channelConsole);
|
FConsoleChannel:=TJSBroadcastChannel.new(channelConsole);
|
||||||
if not isMainBrowserThread then
|
if isMainBrowserThread then
|
||||||
Self_.addEventListener('message',@HandleIncomingMessage);
|
FConsoleChannel.addEventListener('message',@HandleIncomingMessage)
|
||||||
|
else
|
||||||
|
Self_.addEventListener('message',@HandleIncomingMessage)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TCommandDispatcher.destroy;
|
destructor TCommandDispatcher.destroy;
|
||||||
@ -298,6 +304,17 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCommandDispatcher.SendConsoleCommand(aCommand: TConsoleOutputCommand);
|
||||||
|
|
||||||
|
begin
|
||||||
|
if not (isWebWorker or IsServiceWorker) then
|
||||||
|
Raise EWorkerCommand.Create('Cannot send to starting thread from main page');
|
||||||
|
{$IFDEF DEBUGCOMMANDDISPATCHER}
|
||||||
|
Writeln('Sending console message on console channel: 'TJSJSON.stringify(aCommand));
|
||||||
|
{$ENDIF}
|
||||||
|
FConsoleChannel.postMessage(aCommand);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCommandDispatcher.BroadcastCommand(aCommand: TCustomWorkerCommand);
|
procedure TCommandDispatcher.BroadcastCommand(aCommand: TCustomWorkerCommand);
|
||||||
var
|
var
|
||||||
lWorker : TJSWorkerReg;
|
lWorker : TJSWorkerReg;
|
||||||
|
Loading…
Reference in New Issue
Block a user