Skip to content

Commit 1d7b189

Browse files
committed
asyncio_slow: Fix call_soon(), add call_later().
1 parent 5166ecb commit 1d7b189

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

asyncio_slow/asyncio_slow.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,18 @@ def __init__(self):
2121
self.q = []
2222

2323
def call_soon(self, c, *args):
24-
self.q.append(c)
24+
self.q.append((c, args))
25+
26+
def call_later(self, delay, c, *args):
27+
def _delayed(c, args, delay):
28+
yield from sleep(delay)
29+
self.call_soon(c, *args)
30+
Task(_delayed(c, args, delay))
2531

2632
def run_forever(self):
2733
while self.q:
2834
c = self.q.pop(0)
29-
c()
35+
c[0](*c[1])
3036
# I mean, forever
3137
while True:
3238
time.sleep(1)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy