Skip to content

Commit f30d1e2

Browse files
Add async generator API to pywatchman_aio
Summary: Many of the other client libraries have event driven async APIs, but python does not really have that currently. The best it has is `get_subscription` which acts as a polling api as it directly returns `q.get()` instead of returning the queue itself. This diff adds an API to yield elements in the queue so that it can be used as an async generator to make the code more event driven. Test Plan: tbd
1 parent 39fed47 commit f30d1e2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

watchman/python/pywatchman_aio/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,22 @@ async def get_subscription(self, name, root):
258258
self._check_error(res)
259259
return res
260260

261+
async def watch_subscription(self, name, root):
262+
"""Async generator that yields watchman subscription events
263+
264+
If root is not None, then only yield the subscription
265+
data that matches both root and name. When used in this way,
266+
remove processing impacts both the unscoped and scoped stores
267+
for the subscription data.
268+
"""
269+
self._check_receive_loop()
270+
self._ensure_subscription_queue_exists(name, root)
271+
q = self.sub_by_root[root][name]
272+
while res := await q.get():
273+
self._check_error(res)
274+
yield res
275+
276+
261277
async def pop_log(self):
262278
"""Get one log from the log queue."""
263279
self._check_receive_loop()

0 commit comments

Comments
 (0)