Replies: 2 comments
-
In MicroPython, calling an async function without awaiting it right away creates a generator object. You run to completion in your own way. If you have a specific use case, I can elaborate the example with some more detail. from pybricks.tools import multitask, run_task, wait, StopWatch
tasks = []
async def hello(text, duration):
print("Will print", text, "in", duration)
await wait(duration)
print(text)
async def background():
# Build your own mechanics to run created tasks here.
pass
async def main():
# Create "tasks" but don't run them right away
tasks.append(hello("world", 1000))
tasks.append(hello("you", 2000))
tasks.append(hello("me", 3000))
run_task(multitask(main(), background())) Or perhaps you can use |
Beta Was this translation helpful? Give feedback.
-
Not allowing "forked" tasks that are not awaited is by design. This is not something we want to try to support because, in our experience, it just causes too many unexpected behaviors.
Can you give an example where this would be useful? |
Beta Was this translation helpful? Give feedback.
-
I am wondering -and have not found a feasible way yet- to fork an async function from another; and optionally somewhere later wait for it with join.
Is there any way to fork dynamic number of stacks?
In JS I would call the async function without an await, but here it does not seem to so the trick.
Beta Was this translation helpful? Give feedback.
All reactions