如何在 mojo 中实现异步代码(使用asyncetc. )?

在 Changelog 中,我找到了以下示例(略有调整):

How can I implement asynchroneous code in mojo (using async etc.)?

In the Changelog, I find the following example (slightly adjusted):

async fn add_three(a: Int, b: Int, c: Int) -> Int:
    return a + b + c

async fn call_it():
    var task = 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

async fn add_three(a: Int, b: Int, c: Int) -> Int:
    return a + b + c

async fn call_it():
    var task = 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 with the nightly built mojo 2024.7.2005 (96a1562c).

Addon: I asked this question on the Q&A page and on SO some time ago. Sorry for the double posting; I just do not know what is the best way to get in touch with people who can help. I will keep the copies up to date (or delete them if people think this would be better).

Async mojo尚未完全成熟。内部已取得很大进展,敬请期待!

我被指向了另一个频道的答案。我需要在等待时“删除”协程。

async fn add_three(a: Int, b: Int, c: Int) -> Int:
    return a + b + c

async fn call_it():
    var task = add_three(1, 2, 3)
    print(await task^)
 ``


嗯,看起来仍然不是异步的。。。

async fn get_time() -> Float64:
var time = now() * 1e-9
sleep(1)
return time

fn call_it():
var a = get_time()
var b = get_time()

print(await a^)
print(await b^)
如果我们调用call_it,我们会得到 
6 9 1 6 .1215625790001
 6 9 1 7 .1220518390001
因此函数不是并行执行的。好像要等到被await调用。那么我做错了什么?我怎样才能实现异步?
贾巴达胡特50—2024 年 9 月 1 日上午 7:35
async 不是并行计算,而是并发计算。两者经常被混淆,但本质上是不同的。
当 Async 获得它所等待的所有东西并在单个线程上获得一个开口时,它就会运行。因此,等待一个函数意味着它将等待直到它所等待的函数完成并返回后才能继续,然后它将获得返回并完成自己的工作。