surrealdb / surrealdb.go

SurrealDB SDK for Golang
https://surrealdb.com
Apache License 2.0
240 stars 66 forks source link

Refactor on websocket implementation for code quality #27

Closed ffrizzo closed 2 years ago

ffrizzo commented 2 years ago

Update implementation of websocket for code clarity/quality

Have removed channels to reduce code complexity Move the logic of waiting for websocket response to the Send function and this now returns the result or error

⚠️ This PR is based on #25 and on #26. ⚠️ The relevant commit on this one is https://github.com/surrealdb/surrealdb.go/commit/bae20d4af2b438a458d088f1932b7628c889ff8b

tobiemh commented 2 years ago

Hi @ffrizzo - thanks for this PR! Can I ask why the need to remove channels?

EtienneBruines commented 2 years ago

The channels were probably removed because https://github.com/ffrizzo/surrealdb.go/blob/bae20d4af2b438a458d088f1932b7628c889ff8b/internal/websocket/ws.go#L72 handles the "waiting" for the response.

(And as such, the code here does not need to wait for it using channels - it blocks until the response is received from Send.)

ffrizzo commented 2 years ago

Hi @ffrizzo - thanks for this PR! Can I ask why the need to remove channels?

This is more about code quality and simplicity, not related to no-need channels. You can check it here L24-L25 channel still needed but this is implemented in a simpler way