Replies: 5 comments 9 replies
-
I've started using lona to create multiplayer card game. What about having some channel for different views to communicate (a)synchronously? We already have class MultiUserView(LonaView):
def send_message(self, message):
self.fire_server_event(data=message, broadcast=True, wait=False)
def handle_server_event(self, event):
self.messages.append(event.data)
self.show() |
Beta Was this translation helpful? Give feedback.
-
I find both the |
Beta Was this translation helpful? Give feedback.
-
@maratori, @TheMutt: I started implementing While implementing I noticed something: When a views We could add a call to discard all pending input events, or build a combined call like Edit: I pushed the current state of my patches to https://github.com/lona-web-org/lona/tree/fscherf/multi-user |
Beta Was this translation helpful? Give feedback.
-
@maratori Thanks! I think you are right. In this case i think we don't need |
Beta Was this translation helpful? Give feedback.
-
FTR: View events are implemented now |
Beta Was this translation helpful? Give feedback.
-
Hi!
When writing multi-user views,
LonaView.iter_objects()
is used to interact between multiple objects of the same view.This code works fine as long as
send_message
returns fast. If this funtion would do something long runninghandle_request()
would have to wait til all views have sent the message.You can fix this if you use
server.run_function_async()
. I propose a decorator named@run_in_thread
that can be added to all methods of a view, besides the buildin ones (handle_request
,handle_input_event
, etc).If a function decorated like that, gets called, the call directly returns a concurrent future, which can be awaited using
future.result()
if needed. For messaging like in this view, you would just fire and forget.@maratori, @laundmo, @TheMutt, @sobolevn, @korantu: Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions