mirror of
https://github.com/MercuryWorkshop/bare-mux.git
synced 2025-05-16 07:30:01 -04:00
add a ping message to make sure worker port is alive
This commit is contained in:
parent
fde90f3ec1
commit
6e86375a69
2 changed files with 57 additions and 26 deletions
|
@ -18,8 +18,9 @@ function handleConnection(port: MessagePort) {
|
|||
port.onmessage = async (event: MessageEvent) => {
|
||||
const port = event.data.port;
|
||||
const message: WorkerMessage = event.data.message;
|
||||
|
||||
if (message.type === "set") {
|
||||
if (message.type === "ping") {
|
||||
port.postMessage(<WorkerResponse>{ type: "pong" });
|
||||
} else if (message.type === "set") {
|
||||
try {
|
||||
const AsyncFunction = (async function() { }).constructor;
|
||||
|
||||
|
@ -32,6 +33,7 @@ function handleConnection(port: MessagePort) {
|
|||
|
||||
port.postMessage(<WorkerResponse>{ type: "set" });
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
port.postMessage(<WorkerResponse>{ type: "error", error: err });
|
||||
}
|
||||
} else if (message.type === "get") {
|
||||
|
@ -55,6 +57,7 @@ function handleConnection(port: MessagePort) {
|
|||
port.postMessage(<WorkerResponse>{ type: "fetch", fetch: resp });
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
port.postMessage(<WorkerResponse>{ type: "error", error: err });
|
||||
}
|
||||
} else if (message.type === "websocket") {
|
||||
|
@ -98,6 +101,7 @@ function handleConnection(port: MessagePort) {
|
|||
|
||||
port.postMessage(<WorkerResponse>{ type: "websocket" });
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
port.postMessage(<WorkerResponse>{ type: "error", error: err });
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue