You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently working on bidirectional remote procedure call using trio sockets. The abstraction I've been using works like this:
A task is permanently awaiting incoming bytes and sending them through a memory channel.
This memory channel is a special channel that never blocks on send (using math.inf on the constructor) this is the "publisher".
Then anywhere in the code I can create a "subscriber" that will match every message sent through the channel, and if matched will send it through its own channel.
I created a small package calling this abstraction AsyncQueue. The implementation is cool I think, it ends up like a tree-like structure of AsyncQueues.
Also for a real world example boxer, is a UDP Hole punching client/server.
defmatcher(*args):
returnb"hello"inargs[0]
# msg_queue will receive all messages that contain the byte sequence "hello"asyncwithinbound.subscribe(matcher) asmsg_queue:
msg=awaitmsg_queue.receive()
Send a message through:
awaitinbound.send(b"hello world!")
You can also use lambdas for subscriber matcher callbacks:
In the case you need to apply a modification to every message sent when matched, use modifiers:
defstr_matcher(*args):
try:
return (True, str(args[0]))
exceptUnicodeDecodeError:
return (False, None)
asyncwithinbound.modify(str_matcher) asmsg_queue:
# msg will be of type strmsg=awaitmsg_queue.receive()
Woah awesome, just followed over from #467 (comment), I am going to try and take this for a spin now and let you know how it goes. Thanks for getting this out! EDIT: Works! Unfortunately doesn't quiitteee fit my use case.
Activity
decentral1se commentedon May 17, 2020
Woah awesome, just followed over from #467 (comment), I am going to try and take this for a spin now and let you know how it goes. Thanks for getting this out! EDIT: Works! Unfortunately doesn't quiitteee fit my use case.
guilledk commentedon May 17, 2020
Cool! Thanks for trying it out!