1212from typing import Optional , Union
1313
1414import kiwipy
15+ from plumpy .coordinator import Coordinator
1516
1617from aiida .orm import Node , load_node
1718
@@ -28,36 +29,36 @@ def __init__(
2829 pk : int ,
2930 loop : Optional [asyncio .AbstractEventLoop ] = None ,
3031 poll_interval : Union [None , int , float ] = None ,
31- communicator : Optional [kiwipy . Communicator ] = None ,
32+ coordinator : Optional [Coordinator ] = None ,
3233 ):
3334 """Construct a future for a process node being finished.
3435
3536 If a None poll_interval is supplied polling will not be used.
36- If a communicator is supplied it will be used to listen for broadcast messages.
37+ If a coordinator is supplied it will be used to listen for broadcast messages.
3738
3839 :param pk: process pk
3940 :param loop: An event loop
4041 :param poll_interval: optional polling interval, if None, polling is not activated.
41- :param communicator : optional communicator , if None, will not subscribe to broadcasts.
42+ :param coordinator : optional coordinator , if None, will not subscribe to broadcasts.
4243 """
4344 from .process import ProcessState
4445
4546 # create future in specified event loop
4647 loop = loop if loop is not None else asyncio .get_event_loop ()
4748 super ().__init__ (loop = loop )
4849
49- assert not (poll_interval is None and communicator is None ), 'Must poll or have a communicator to use'
50+ assert not (poll_interval is None and coordinator is None ), 'Must poll or have a coordinator to use'
5051
5152 node = load_node (pk = pk )
5253
5354 if node .is_terminated :
5455 self .set_result (node )
5556 else :
56- self ._communicator = communicator
57+ self ._coordinator = coordinator
5758 self .add_done_callback (lambda _ : self .cleanup ())
5859
5960 # Try setting up a filtered broadcast subscriber
60- if self ._communicator is not None :
61+ if self ._coordinator is not None :
6162
6263 def _subscriber (* args , ** kwargs ):
6364 if not self .done ():
@@ -66,17 +67,17 @@ def _subscriber(*args, **kwargs):
6667 broadcast_filter = kiwipy .BroadcastFilter (_subscriber , sender = pk )
6768 for state in [ProcessState .FINISHED , ProcessState .KILLED , ProcessState .EXCEPTED ]:
6869 broadcast_filter .add_subject_filter (f'state_changed.*.{ state .value } ' )
69- self ._broadcast_identifier = self ._communicator .add_broadcast_subscriber (broadcast_filter )
70+ self ._broadcast_identifier = self ._coordinator .add_broadcast_subscriber (broadcast_filter )
7071
7172 # Start polling
7273 if poll_interval is not None :
7374 loop .create_task (self ._poll_process (node , poll_interval ))
7475
7576 def cleanup (self ) -> None :
76- """Clean up the future by removing broadcast subscribers from the communicator if it still exists."""
77- if self ._communicator is not None :
78- self ._communicator .remove_broadcast_subscriber (self ._broadcast_identifier )
79- self ._communicator = None
77+ """Clean up the future by removing broadcast subscribers from the coordinator if it still exists."""
78+ if self ._coordinator is not None :
79+ self ._coordinator .remove_broadcast_subscriber (self ._broadcast_identifier )
80+ self ._coordinator = None
8081 self ._broadcast_identifier = None
8182
8283 async def _poll_process (self , node : Node , poll_interval : Union [int , float ]) -> None :
0 commit comments