Skip to content

Async WebSockets #959

Answered by quinnj
oliviermilla asked this question in Q&A
Nov 7, 2022 · 4 comments · 2 replies
Discussion options

You must be logged in to vote

I'd recommend taking a look at the WebSockets documentation; particularly, we recommend this following pattern:

WebSockets.open(url) do ws
    for msg in ws
        # do cool stuff with msg
    end
end

For async, you can just wrap that block with the @async macro and store the task to inspect later if needed:

websocket_client_task = @async WebSockets.open(url) do ws
    for msg in ws
        # do cool stuff with msg
    end
end

Replies: 4 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by oliviermilla
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@quinnj
Comment options

@oliviermilla
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #958 on November 07, 2022 18:56.