kopia lustrzana https://github.com/micropython/micropython-lib
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
rodzic
b4b19f1dce
commit
c60ff8125b
|
@ -44,12 +44,6 @@ class EventLoop:
|
||||||
log.debug("Sleeping for: %s", delay)
|
log.debug("Sleeping for: %s", delay)
|
||||||
time.sleep(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):
|
def run_forever(self):
|
||||||
while True:
|
while True:
|
||||||
if self.q:
|
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 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(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(), lambda cb: self.call_soon(cb), cb)
|
||||||
self.add_reader(arg.fileno(), self.lambda_helper(cb))
|
self.add_reader(arg.fileno(), cb)
|
||||||
continue
|
continue
|
||||||
elif isinstance(ret, IOWrite):
|
elif isinstance(ret, IOWrite):
|
||||||
# self.add_writer(arg.fileno(), lambda cb: self.call_soon(cb), cb)
|
# 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
|
continue
|
||||||
elif isinstance(ret, IOReadDone):
|
elif isinstance(ret, IOReadDone):
|
||||||
self.remove_reader(arg.fileno())
|
self.remove_reader(arg.fileno())
|
||||||
|
|
Ładowanie…
Reference in New Issue