extmod/uasyncio: Truncate negative sleeps to 0.

Otherwise a task that continuously awaits on a large negative sleep can
monopolise the scheduler (because its wake time is always less than
everything else in the pairing heap).

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2020-08-20 23:13:25 +10:00
parent 20948a3d54
commit 55c76eaac1
3 changed files with 3 additions and 1 deletions

View File

@@ -53,7 +53,7 @@ class SingletonGenerator:
# Use a SingletonGenerator to do it without allocating on the heap
def sleep_ms(t, sgen=SingletonGenerator()):
assert sgen.state is None
sgen.state = ticks_add(ticks(), t)
sgen.state = ticks_add(ticks(), max(0, t))
return sgen