M
Modular14mo ago
뽀삐2

how to use async in mojo?

async fn add_three(a: Int, b: Int, c: Int) -> Int:
let sum:Int = a + b + c;
return sum

async fn main():
let task: Coroutine[Int] = add_three(1, 2, 3)
let result:Int = await task
print(result)
async fn add_three(a: Int, b: Int, c: Int) -> Int:
let sum:Int = a + b + c;
return sum

async fn main():
let task: Coroutine[Int] = add_three(1, 2, 3)
let result:Int = await task
print(result)
I did what mojo bot told me to do, but I got the error below.
/__w/modular/modular/Kernels/mojo/builtin/_startup.mojo:70:1: error: caller input parameter #0 has type '!kgen.signature<() async -> !lit.none>' but callee expected type '!kgen.signature<() -> !lit.none>'
mojo: error: failed to run the pass manager
/__w/modular/modular/Kernels/mojo/builtin/_startup.mojo:70:1: error: caller input parameter #0 has type '!kgen.signature<() async -> !lit.none>' but callee expected type '!kgen.signature<() -> !lit.none>'
mojo: error: failed to run the pass manager
4 Replies
jmky
jmky14mo ago
i think you need to do await task()
Alex Kirchhoff
Alex Kirchhoff14mo ago
The current version of Mojo does not support main being marked as async. You can cause coroutines to be executed on the calling thread by calling them (e.g. let result: Int = task()), but this kind of defeats the whole point of async. There is not really much you can do with async in Mojo right now until we build out more of the infrastructure around it.
silverviolin.
silverviolin.9mo ago
@Alex Kirchhoff May I ask about our usage plan for async based on coroutines, which version of mojo is expected to achieve the effect of immediate execution?
miilirgur
miilirgur9mo ago
python
Want results from more Discord servers?
Add your server