You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How can I implement asynchroneous code in mojo (using async etc.)?
In the Changelog, I find the following example (slightly adjusted):
asyncfnadd_three(a: Int, b: Int, c: Int) -> Int:
return a + b + c
asyncfncall_it():
vartask= add_three(1, 2, 3)
print(await task)
This gives me the following compiler error:
test_async.mojo:39:17: error: 'Coroutine[Int, {}]' is not copyable because it has no '__copyinit__'
print(await task)
^~~~
I do not understand this error, as I thought that Coroutine is register passable (as visible in the source code). What works is
asyncfnadd_three(a: Int, b: Int, c: Int) -> Int:
return a + b + c
asyncfncall_it():
vartask=await add_three(1, 2, 3)
print(task)
However, if I always put await on the right hand side, I will never be able to execute code asynchroneously, as I am always waiting until the line has finished. What am I doing wrong / where is my misconception? (Or is this simply a bug?)
In the changelog it furthermore says that tasks can be "resumed" after completion (see here). What is meant by "resume" and how do I do that?
I am working on the current nightly built: mojo 2024.7.2005 (96a1562c).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
How can I implement asynchroneous code in mojo (using
async
etc.)?In the Changelog, I find the following example (slightly adjusted):
This gives me the following compiler error:
I do not understand this error, as I thought that
Coroutine
is register passable (as visible in the source code). What works isHowever, if I always put
await
on the right hand side, I will never be able to execute code asynchroneously, as I am always waiting until the line has finished. What am I doing wrong / where is my misconception? (Or is this simply a bug?)In the changelog it furthermore says that tasks can be "resumed" after completion (see here). What is meant by "resume" and how do I do that?
I am working on the current nightly built: mojo 2024.7.2005 (96a1562c).
Beta Was this translation helpful? Give feedback.
All reactions