-
Notifications
You must be signed in to change notification settings - Fork 57
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
create_connection, send and recv instead of simply open / avoid do statements #185
Comments
Hello, femtotrader. I think I understand your dislike of do-functions. You find remnants of my own reluctance in this repository. They may mature on you, as they did for me, but in the meantime, I suggest you rewrite:
What you ask for is possible, although it breaks with a couple of practices that are common in Julia although they also increase your chance to 'monitor as things happen'. You are going to make You can basically dissect the function Your thread of execution can of course easily get stuck in waiting forever for the other side (while the other side may be waiting for you). If you don't want that to happen, execute functions with I believe using this package as you do is ok for easing the transition. If you plan on doing something larger or permanent, though, I actually recommend you have a look at HTTP.jl. That one is the long-term solution for websockets in Julia, although we maintain this in order to keep other useful, old packages alive. I'm pinging @fonsp here, as this issue relates to a discussion we had recently. |
Thanks @hustf for your very detailed answer. I was expecting something like this would be possible: const url = "wss://ws.kraken.com/"
ws_client = WebSockets.open(url)
msg = Dict(
"event" => "subscribe",
"subscription" => Dict("name" => "trade"),
"pair" => ["XBT/USDT", "XBT/USD"]
)
msg = JSON.json(msg)
writeguarded(ws_client, msg)
while (true)
data, success = readguarded(ws_client)
if success
println(stderr, ws_client, " received:", String(data))
end
end
close(ws_client) because with such a rewrite it would be easier to reuse WebSockets.jl in a quite complex project. I will try using REPL and Line 68 in 811d94b
|
Good luck! |
Hello,
Sorry I'm new to websockets.
I want to convert the following Python code to Julia
I did using doc
but I don't like Julia
do
statements.Moreover I would prefer to have separate
create_connection
,send
andrecv
call like in the Python example but in the Julia exampleopen
takes handle function as parameter which is a mix of all this.How can I achieve that? (ie having a Julia code nearer than the Python code)
Kind regards
The text was updated successfully, but these errors were encountered: