Re:Portable and Interoperable Async Rust
by zaphar on Thursday December 09, 2021 @02:45PM
(#29501995)
Close. If I execute say want to run some function asynchronously I use the go keyword to execute it. But I can't get a return value if I do that so I need some other mechanism to get the return value. One way is to pass a channel into the function and expect the function to return the value to me via that channel. like so:
then I can call that function asynchronously
and later when I want the value from f I can retrieve it from the channel
The net effect of the all the above is that async and non async code is highly composable. if I have a function that computes a value and I want to get that value asynchronously then I can wrap it in a function that uses a channel to get the value to me.
Every function is a potential asynchronous function.
[ Parent
| on HN ]
Re:Portable and Interoperable Async Rust
by KingOfCoders on Saturday December 11, 2021 @08:25AM
(#29520698)
"The net effect of the all the above is that async and non async code is highly composable."
How does this differ from Rust (Or Typescript etc.) where we would use
async f() -> i32 { }
fn g() { f().wait() }
to block?
Re:Portable and Interoperable Async Rust
by KingOfCoders on Saturday December 11, 2021 @04:19AM
(#29519633)
Thanks a lot! Can only upvote you once sadly.