uasyncio.core: Avoid wrapping coroutines to lambdas for add_reader/writer.

add_reader/writer default behavior is to schedule "callback" on I/O
completion via call_soon(), there's no need to have lambda for that.
pull/65/merge
Paul Sokolovsky 2015-12-12 00:12:19 +02:00
rodzic b4b19f1dce
commit c60ff8125b
1 zmienionych plików z 2 dodań i 8 usunięć

Wyświetl plik

@ -44,12 +44,6 @@ class EventLoop:
log.debug("Sleeping for: %s", delay)
time.sleep(delay)
# Workaround bug for in uPy - default args for lambda's are not supported
def lambda_helper(self, cb):
def lmb(cb=cb):
self.call_soon(cb)
return lmb
def run_forever(self):
while True:
if self.q:
@ -85,11 +79,11 @@ class EventLoop:
# self.add_reader(ret.obj.fileno(), lambda self, c, f: self.call_soon(c, f), self, cb, ret.obj)
# self.add_reader(ret.obj.fileno(), lambda c, f: self.call_soon(c, f), cb, ret.obj)
# self.add_reader(arg.fileno(), lambda cb: self.call_soon(cb), cb)
self.add_reader(arg.fileno(), self.lambda_helper(cb))
self.add_reader(arg.fileno(), cb)
continue
elif isinstance(ret, IOWrite):
# self.add_writer(arg.fileno(), lambda cb: self.call_soon(cb), cb)
self.add_writer(arg.fileno(), self.lambda_helper(cb))
self.add_writer(arg.fileno(), cb)
continue
elif isinstance(ret, IOReadDone):
self.remove_reader(arg.fileno())