我在学习 Rust ,我原来是学习Go的。
使用 Go 很容易在 goroutine 中启动一个函数,即使我返回父函数,例如:
用代码块功能插入代码,请勿粘贴截图
func doSomething() {
// do something
go func() {
// do something longer
// this doesn't block doSomething and also handles optional errors
}()
return // something
}
我怎样才能在 Rust 中做到这一点?
假设我有这个代码:
#[tokio::main]
async fn main() {
doSomething().await;
}
async fn doSomething() {
// do something
// How to start something longer here?
// I don't want to block doSomething function here, this is only a background task I need to start.
return // something
}