From 1d7b189e7579a5c3e3f4e3f5b7ed7b7956866a27 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 1 May 2014 23:20:44 +0300 Subject: [PATCH] asyncio_slow: Fix call_soon(), add call_later(). --- asyncio_slow/asyncio_slow.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/asyncio_slow/asyncio_slow.py b/asyncio_slow/asyncio_slow.py index ef21708f..bf82fcac 100644 --- a/asyncio_slow/asyncio_slow.py +++ b/asyncio_slow/asyncio_slow.py @@ -21,12 +21,18 @@ class EventLoop: self.q = [] 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): while self.q: c = self.q.pop(0) - c() + c[0](*c[1]) # I mean, forever while True: time.sleep(1)