Skip to content

[Feature] asyncio.Event (or other way to let one coroutine block on another) #2444

@abliss

Description

@abliss

Is your feature request related to a problem? Please describe.
When using multitasking, I would like to have one coroutine block to await something happening in another coroutine. Currently I think I have to setup a sleeping-wait loop for this, which is unsatisfactory because lower sleep amounts waste resources and higher sleep amounts make the latency worse.
I see that uselect offers polling but apparently only for FileIO streams, so it's not clear if I can use this to do what I want.

Describe the solution you'd like
I'd like to be able to instantiate an asyncio.Event object as described in https://docs.micropython.org/en/latest/library/asyncio.html#class-event so that one coroutine can event.clear(); await event.wait() and a second coroutine can run event.set() when it's ready to unblock the first one.
Describe alternatives you've considered
I tried running the above code on the spike prime hub but it said no module named 'asyncio'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    software: pybricks-micropythonIssues with Pybricks MicroPython firmware (or EV3 runtime)topic: MicroPythonIssues related to the MicroPython programming languagetopic: multitaskingIssues releated to parallel threads, tasks, coroutines, etc.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions