@@ -67,7 +67,7 @@ def is_block(self) -> None:
6767
6868@dataclass
6969class AwaitBlock :
70- fut : Future
70+ futs : list [ Future ]
7171 line : int
7272
7373 def is_block (self ) -> None :
@@ -139,7 +139,7 @@ def body_labeled(line: int, label: str, *stmts: Block) -> BodyLabeledBlock:
139139
140140
141141def await_block (line : int , start : StartFunc , trigger : TriggerFunc ) -> AwaitBlock :
142- return AwaitBlock (fut = Future (start = start , trigger = trigger ), line = line )
142+ return AwaitBlock (futs = [ Future (start = start , trigger = trigger )] , line = line )
143143
144144
145145def sync (line : int , stmt : Callable [[Context ], None ]) -> SyncBlock :
@@ -228,6 +228,39 @@ def _trigger(ctx: Context, notify: EventNotify) -> None:
228228 return await_block (line , _start , _trigger )
229229
230230
231+ def recv_any (
232+ line : int ,
233+ count : int ,
234+ ids : Callable [[Context ], list [str ]],
235+ ref : Callable [[Context , bytes , int ], None ],
236+ ) -> AwaitBlock :
237+ def _make_future (idx : int ) -> Future :
238+ def _start (ctx : Context ) -> Event :
239+ return ChannelRecvEvent (id = ids (ctx )[idx ])
240+
241+ def _trigger (ctx : Context , notify : EventNotify ) -> None :
242+ if hasattr (notify , "value" ):
243+ ref (ctx , notify .value , idx )
244+
245+ return Future (start = _start , trigger = _trigger )
246+
247+ return AwaitBlock (futs = [_make_future (i ) for i in range (count )], line = line )
248+
249+
250+ def deser (
251+ line : int ,
252+ data : Callable [[Context ], bytes ],
253+ type_ : type ,
254+ ret : Callable [[Context , Any ], None ],
255+ ) -> SyncBlock :
256+ def _stmt (ctx : Context ) -> None :
257+ origin = get_origin (type_ )
258+ value = msgspec .msgpack .decode (data (ctx ), type = origin if origin else type_ )
259+ ret (ctx , value )
260+
261+ return sync (line , _stmt )
262+
263+
231264def recv (
232265 line : int ,
233266 id : Callable [[Context ], str ],
0 commit comments