@@ -128,7 +128,7 @@ async def main():
128128 managing_actor = ActorDispatcher(
129129 actor_factory=MyActor.new_with_dispatch,
130130 running_status_receiver=status_receiver,
131- map_dispatch =lambda dispatch: dispatch .id,
131+ dispatch_identity =lambda d: d .id,
132132 )
133133
134134 await run(managing_actor)
@@ -139,18 +139,19 @@ def __init__(
139139 self ,
140140 actor_factory : Callable [[DispatchInfo , Receiver [DispatchInfo ]], Actor ],
141141 running_status_receiver : Receiver [Dispatch ],
142- map_dispatch : Callable [[Dispatch ], int ],
142+ dispatch_identity : Callable [[Dispatch ], int ],
143143 ) -> None :
144144 """Initialize the dispatch handler.
145145
146146 Args:
147147 actor_factory: A callable that creates an actor with some initial dispatch
148148 information.
149149 running_status_receiver: The receiver for dispatch running status changes.
150- map_dispatch: A function to identify to which actor a dispatch refers.
150+ dispatch_identity: A function to identify to which actor a dispatch refers.
151+ By default, it uses the dispatch ID.
151152 """
152153 super ().__init__ ()
153- self ._map_dispatch = map_dispatch
154+ self ._dispatch_identity = dispatch_identity
154155 self ._dispatch_rx = running_status_receiver
155156 self ._actor_factory = actor_factory
156157 self ._actors : dict [int , Actor ] = {}
@@ -171,7 +172,7 @@ async def _start_actor(self, dispatch: Dispatch) -> None:
171172 options = dispatch .payload ,
172173 )
173174
174- actor : Actor | None = self ._actors .get (self ._map_dispatch (dispatch ))
175+ actor : Actor | None = self ._actors .get (self ._dispatch_identity (dispatch ))
175176
176177 if actor :
177178 sent_str = ""
@@ -189,7 +190,7 @@ async def _start_actor(self, dispatch: Dispatch) -> None:
189190 dispatch_update ,
190191 self ._updates_channel .new_receiver (limit = 1 , warn_on_overflow = False ),
191192 )
192- self ._actors [self ._map_dispatch (dispatch )] = actor
193+ self ._actors [self ._dispatch_identity (dispatch )] = actor
193194
194195 actor .start ()
195196
@@ -200,7 +201,7 @@ async def _stop_actor(self, stopping_dispatch: Dispatch, msg: str) -> None:
200201 stopping_dispatch: The dispatch that is stopping the actor.
201202 msg: The message to be passed to the actors being stopped.
202203 """
203- if actor := self ._actors .pop (self ._map_dispatch (stopping_dispatch ), None ):
204+ if actor := self ._actors .pop (self ._dispatch_identity (stopping_dispatch ), None ):
204205 await actor .stop (msg )
205206 else :
206207 _logger .warning (
0 commit comments