rsocket / rsocket-js

JavaScript implementation of RSocket
https://github.com/rsocket/rsocket-js
Apache License 2.0
594 stars 97 forks source link

feat: allow closing a WebSocket server outside of the ServerCloseable #279

Open stevensJourney opened 2 months ago

stevensJourney commented 2 months ago

Allows for not managing closing of the WebSocket server externally from the ServerCloseable.

Motivation:

In my use case I provide an existing WebSocket server using the wsCreator factory. This server's lifecycle is managed externally.

In the current implementation if I close my WebSocket server externally then the close listener will trigger the ServerCloseable's close method which will attempt to close the server again which will fire another close event and trigger the ServerCloseable's close method for a second time: this prints a warning for attempting to close for the second time.

Modifications:

I've added an option to externally manage closing of the server. This will optionally prevent the ServerCloseable from closing the server.

Result:

An additional option will be available when creating a WebSocketServerTransport. If this option is enabled the WebSocketServer should be closed externally.

viglucci commented 2 months ago

Hey @stevensJourney -- thanks for these PRs. I'm working on adding test coverage to the affected files. Ideally you can update your fork with the tests once they exist, and then I'll loop back around to reviewing your changes.

stevensJourney commented 2 months ago

Hey @stevensJourney -- thanks for these PRs. I'm working on adding test coverage to the affected files. Ideally you can update your fork with the tests once they exist, and then I'll loop back around to reviewing your changes.

Thanks for the quick response @viglucci . I'm happy to assist wherever possible with the approach suggested. Thanks for all the great work!