nvbn / microasync

Green threads and CSP for micropython
5 stars 1 forks source link

Any reason for not using uasyncio from MicroPython stdlib? #1

Open pfalcon opened 10 years ago

pfalcon commented 10 years ago

subj. https://github.com/micropython/micropython-lib/tree/master/uasyncio.core

nvbn commented 10 years ago

I started microasync when uasyncio not existed, so I think I should try uasyncio =) Thanks for the link.

pfalcon commented 10 years ago

Well, first commit was in April: https://github.com/micropython/micropython-lib/commit/80ecd3b822973352fa75d7166bf689c4284f8d38 , soon after I finished implementing "yield from": https://github.com/micropython/micropython/commit/cf21a4e7f4fbd330fa65fb5431308ae712626023 . Forum thread dates to start of May: http://forum.micropython.org/viewtopic.php?f=3&t=85 .

Bottom line: would be nice to get people interested in coroutine multitasking in MicroPython on the same line to move it forward ;-). uasyncio now has web microframework running on top of it: https://github.com/pfalcon/picoweb . But that runs on POSIX port, I really could use some help with supporting PyBoard I/O in event loop.

nvbn commented 9 years ago

I've tried uasyncio.core and it works well on simple code like:

from uasyncio.core import get_event_loop, sleep
import pyb

def toggle_led_on_interval(led, interval):
    while True:
        pyb.LED(led).toggle()
        yield from sleep(interval)

loop = get_event_loop()
loop.call_soon(toggle_led_on_interval(1, 1))
loop.call_soon(toggle_led_on_interval(2, 2))
loop.call_soon(toggle_led_on_interval(3, 1))
loop.call_soon(toggle_led_on_interval(4, 2))

loop.run_forever()

So I definitely should use asyncio.core.

pfalcon commented 9 years ago

Thanks! There's a discussion about next steps to support PyBoard devices in uasyncio, which really could use input from more parties: http://forum.micropython.org/viewtopic.php?f=3&t=85&start=30#p2351