-
Notifications
You must be signed in to change notification settings - Fork 13
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
feat: lazy websocket connection #393
base: master
Are you sure you want to change the base?
Conversation
28949a4
to
00565e4
Compare
only create actual websocket connection when there are pending swaps and close it if there are no more pending swaps
00565e4
to
78401ae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It really feels like there should be locks on the pieces of code that touch the state of the websocket. The enum states that represent the state are not clear and the logic inside of the Connect
function is getting way too complex and should be split up.
if boltz.state == closed { | ||
return errors.New("websocket is closed") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't we connect again when a websocket was closed once?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the close call also causes the updates channel to be closed. Its not closed in this call to avoid a situation where we just got a message in the receiving goroutine and would then send on a closed channel
@@ -201,6 +219,11 @@ func (boltz *Websocket) subscribe(swapIds []string) error { | |||
} | |||
|
|||
func (boltz *Websocket) Subscribe(swapIds []string) error { | |||
if boltz.state == disconnected { | |||
if err := boltz.Connect(); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a check here for len(swapIds) > 0
to make sure that we don't open and close the websocket instantly afterwards
only create actual websocket connection when there are pending swaps and
close it if there are no more pending swaps