Skip to content

Commit

Permalink
used async for observe values in observe_value
Browse files Browse the repository at this point in the history
  • Loading branch information
ZohebShaikh committed Oct 22, 2024
1 parent cda91ec commit 492d303
Showing 1 changed file with 4 additions and 25 deletions.
29 changes: 4 additions & 25 deletions src/ophyd_async/core/_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,31 +463,10 @@ async def observe_value(
async for value in observe_value(sig):
do_something_with(value)
"""

q: asyncio.Queue[T | Status] = asyncio.Queue()
if timeout is None:
get_value = q.get
else:

async def get_value():
return await asyncio.wait_for(q.get(), timeout)

if done_status is not None:
done_status.add_callback(q.put_nowait)

signal.subscribe_value(q.put_nowait)
try:
while True:
item = await get_value()
if done_status and item is done_status:
if exc := done_status.exception():
raise exc
else:
break
else:
yield cast(T, item)
finally:
signal.clear_sub(q.put_nowait)
async for _, value in observe_signals_values(
signal, timeout=timeout, done_status=done_status
):
yield value


async def observe_signals_values(
Expand Down

0 comments on commit 492d303

Please sign in to comment.