connector: wanted(port) says whether anyone watches or reads a port
This commit is contained in:
@@ -58,6 +58,20 @@ class Demand:
|
||||
with self._lock:
|
||||
return set().union(*self._wanted.values())
|
||||
|
||||
def wants(self, names: set[str]) -> bool:
|
||||
"""Whether a socket views, or a running flow reads, any of ``names``.
|
||||
|
||||
What a connector's camera asks before it fetches a frame. True while
|
||||
nothing is bound, which is a worker process: the sockets are in the
|
||||
engine's, out of its sight.
|
||||
"""
|
||||
controller = self._controller
|
||||
if controller is None:
|
||||
# ponytail: a remote worker always sends; forward demand to workers
|
||||
# when a camera placed on one costs too much.
|
||||
return True
|
||||
return bool(names & (self.viewed() | controller.consumed_messages()))
|
||||
|
||||
def ports(self, device_id: str) -> list[str]:
|
||||
"""The device's ports that have demand, sorted."""
|
||||
return list(self._compute().get(device_id, ()))
|
||||
|
||||
Reference in New Issue
Block a user