kopia lustrzana https://github.com/micropython/micropython-lib
asyncio_slow: Fix call_soon(), add call_later().
rodzic
c78c27c1dd
commit
6c419ad0ec
|
@ -21,12 +21,18 @@ class EventLoop:
|
||||||
self.q = []
|
self.q = []
|
||||||
|
|
||||||
def call_soon(self, c, *args):
|
def call_soon(self, c, *args):
|
||||||
self.q.append(c)
|
self.q.append((c, args))
|
||||||
|
|
||||||
|
def call_later(self, delay, c, *args):
|
||||||
|
def _delayed(c, args, delay):
|
||||||
|
yield from sleep(delay)
|
||||||
|
self.call_soon(c, *args)
|
||||||
|
Task(_delayed(c, args, delay))
|
||||||
|
|
||||||
def run_forever(self):
|
def run_forever(self):
|
||||||
while self.q:
|
while self.q:
|
||||||
c = self.q.pop(0)
|
c = self.q.pop(0)
|
||||||
c()
|
c[0](*c[1])
|
||||||
# I mean, forever
|
# I mean, forever
|
||||||
while True:
|
while True:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
Ładowanie…
Reference in New Issue