-
-
Notifications
You must be signed in to change notification settings - Fork 258
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
Add async support in WS #134
Conversation
✔️ Deploy Preview for robyn canceled. 🔨 Explore the source changes: 6a3c22e 🔍 Inspect the deploy log: https://app.netlify.com/sites/robyn/deploys/61c0276ab88ebd0008291261 |
I would not recommend doing ctx.spawn, websocket messages may be handled out of order due to scheduling. |
@ShadowJonathan , |
It's mostly so that message B doesn't get processed after message A, I suggest doing the |
@ShadowJonathan , I tried converting this function(https://github.com/sansyrox/robyn/pull/134/files#diff-0d0da7574dadb5452e2f359138c914a901f38425138f1c2facc37f403b98ab7fR38) to an async function but it is not supported by Actix at the moment :( Correct me if I am missing something. |
Ooooh wait, that explains it some more, yes, then this approach should be fine enough. Maybe warn users that websocket message handling can be concurrent, and doesn't wait for each handler to complete before spawning the next one. Or, you could maybe use |
Perfect!
This makes sense. If someone wants to have synchronous execution, they can use regular sync functions whereas the async functions can be used when the order does not matter. This would give a more concurrent feel imo. |
(I recommend trying out that |
But won't it block the execution of other calls while the current call is completed? |
As far as i see it, it blocks the current task until the asyncio future is completed, so it'll wait until the python async function has handled this message first before it moves on to the next. Documentation says the actor wont receive any new messages during this time. |
Hmm.. This is something I didn't want to happen for I am taking inspiration from expressjs or fastifyjs where async functions may execute out of order to provide a more non-blocking experience. Sync functions are always executed in order. |
Just looked up a bunch more documentation from actix, i think it's fine to If you're doing Edit: Looking some more, "actor cannot receive messages at this time" is probably exactly what you want in this situation, because then the websocket stream will be halted until the python async function has been handled. |
Add more support for create, close and message
213cc86
to
b40e2e0
Compare
I feel maybe I am unable to articulate my point or I am unable to understand why order would be beneficial here. 😅 I'll try again: I feel that "halting" would block the socket. Which, IMO, should be restricted to synchronous functions. Async functions "should" work out of order without blocking. |
Now, that I think if the order is really important in async functions. I can just add a param called |
Description
This PR fixes #116