Skip to content

Commit c7702d7

Browse files
committed
v3/as_drivers/sched schedule now returns callback result.
1 parent 5ea8746 commit c7702d7

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

v3/as_drivers/sched/sched.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ async def schedule(func, *args, times=None, **kwargs):
1717
tw = min(tw, maxt)
1818
await asyncio.sleep(tw)
1919
tw -= maxt
20-
launch(func, args)
20+
res = launch(func, args)
2121
if times is not None:
2222
times -= 1
2323
await asyncio.sleep_ms(1200) # ensure we're into next second
24+
return res

v3/docs/SCHEDULE.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ To run error-free a bare metal target should be used for the reason discussed
8585
# 4. The schedule function
8686

8787
This enables a callback or coroutine to be run at intervals. The callable can
88-
be specified to run once only. `schedule` is an asynchronous function.
88+
be specified to run forever, once only or a fixed number of times. `schedule`
89+
is an asynchronous function.
8990

9091
Positional args:
9192
1. `func` The callable (callback or coroutine) to run.
@@ -104,8 +105,11 @@ are shown as inclusive ranges.
104105
7. `times=None` If an integer `n` is passed the callable will be run at the
105106
next `n` scheduled times. Hence a value of 1 specifies a one-shot event.
106107

107-
The `schedule` function only terminates if `times` is not `None`, and then
108-
typically after a long time. Consequently `schedule` is usually started with
108+
The `schedule` function only terminates if `times` is not `None`. In this case
109+
termination occurs after the last run of the callable and the return value is
110+
the value returned by that run of the callable.
111+
112+
Because `schedule` does not terminate promptly it is usually started with
109113
`asyncio.create_task`, as in the following example where a callback is
110114
scheduled at various times. The code below may be run by issuing
111115
```python

0 commit comments

Comments
 (0)