samchon / tgrid

TypeScript RPC (Remote Procedure Call) for WebSocket and Worker protocols
https://tgrid.com/
MIT License
146 stars 19 forks source link

WorkerServer.join() is not working (Also SharedWorkerAcceptor) #19

Closed samchon closed 5 years ago

samchon commented 5 years ago

Summary

WorkerServer is a class constructed in the Worker instance. The Worker instance would be destroyed directly when the main program closes it. Thus, WorkerServer.join() cannot be run. Also, SharedWorkerAcceptor.join() does not work when the exited client was the last browser.

Code occuring the bug

index.ts

import { WorkerConnector } from "tgrid/protocols/workers/WorkerConnector";

async function main(): Promise<void>
{
    let connector: WorkerConnector();
    await connector.connect(__dirname + "/server.js");

    await connector.join();
}
main();

server.ts

import { WorkerServer } from "tgrid/protocols/workers/WorkerServer";

async function main(): Promise<void>
{
    let server: WorkerServer = new WorkerServer();
    await server.open();
    await server.join();

    console.log("Cannot reach to this code");
    console.log("The program would be terminated before");
}
main();