Skip to content
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

The behavior where receiveDataMessage blocks execution isn't documented. #221

Open
techmindful opened this issue Nov 16, 2021 · 1 comment

Comments

@techmindful
Copy link

The documentation of this function here doesn't mention how it blocks execution, until a message is received from the websocket. This can cause confusion.

@flip111
Copy link

flip111 commented Feb 20, 2023

Hi i know this question is a bit old but i was wondering the same. So far i found out that receiveDataMessage doesn't block "especially". Yes it's recursive for control message but a normal message it returns. It does block the same receive and receiveData blocks.

Blocking works on makeSocketStream eventually you will get into socket code recvBuf and friends which use functions from base throwErrnoIfRetryMayBlock.

Where it creates the actual blocking functionality (yielding thread control until next packet comes in), i haven't been able to find.

Also note that the code on the front page

meow :: WS.Connection -> IO ()
meow conn = forever $ do
    msg <- WS.receiveData conn
    WS.sendTextData conn $ msg `T.append` ", meow"

has it's own "blocking" going on with forever. That seems to be just a design choice of this library that you have to create your own loops. I'm not sure how you would break out of that forever loop, possibly after closing the connection either the receive or send function will throw an exception. (i assume but didn't test).

Hope this helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants