-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to close websocket connection? #2
Comments
Hi, @svirmi Thank you for your encouragement, your support makes me feel that those times were not in vain. This is a very good question, and your understanding is correct. Regarding So, the question of 'graceful close' is upgraded to the question of 'who will pass the close signal.' As the saying goes: Do not communicate by sharing memory; instead, share memory by communicating. Therefore, just use |
Well, I thought about it for a while, and then, I feel your question is quite representative; the question you raised is indeed a very good one. From the caller's perspective, something like the following might be more user-friendly: cli, err := bnMarketWs.NewSpotMarketStreamClient(&bnMarketWs.SpotMarketStreamCfg{
Debug: true,
Logger: slog.Default(),
BaseURL: bnMarketWs.SpotMarketStreamBaseURL,
})
if err != nil {
return nil, err
}
err = cli.Open()
if err != nil {
return nil, err
}
// adding topics and listeners
// some other code
err = cli.Close()
if err != nil {
return nil, err
} I will consider adopting this approach in subsequent iterations. |
Hello Linsto!
Thank you for such an interesting library!
Can you please advice how to gracefully close websocket connection and to gracefully exit?
I did it like below, but not sure if it is the right way:
So I guess it should probably close WS connection via context?
Thank you!
The text was updated successfully, but these errors were encountered: