connector: wanted(port) says whether anyone watches or reads a port

This commit is contained in:
Melvin Strobl
2026-10-27 15:20:24 +01:00
parent 7b453af3fe
commit 00cda9d2f1
4 changed files with 68 additions and 0 deletions
+14
View File
@@ -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, ()))