samchon / tgrid

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

Enhance WebConnector.connect() method through Latch #37

Closed samchon closed 4 years ago

samchon commented 4 years ago

Looking at implementation code of WebConnector.connect(), you can see that the method is synchronized through Promise pattern. However, the implementation seems dangerous because sequence of the synchronization are separated to many parts and those separated codes make the implementation code complicate.

To simplify the WebConnector.connect() method without damaging the synchronization, it would better to utilizing Latch class, who is a type of thread supporting component and newly added to C++20 and TSTL v2.3. Implementation code of the WebConnector.connect() method can be much simple through the Latch.wait_for() and Latch.count_down() method.