zlacker

[parent] [thread] 0 comments
1. SkiFir+(OP)[view] [source] 2024-01-20 09:17:40
> I guess I'm just confused that it's labeled async (and does async work) but is actually blocking when invoked (or at least doesn't return until await finishes).

From the point of view of the `async` block/function, it is blocking, but from the point of view of the thread executing that `async` block/function it is not.

> If I'm awaiting on two different results, I have to invoke them in parallel somehow, right?

No, the whole point of `async` is having concurrency (i.e. multiple tasks running and interleaving) without necessarily using parallelism for it. Take a look at the `join` macro in the `futures` crate for example, it allows you to `.await` two futures while allowing both of them to make progress (two successive `.await`s would force the first one to end before the second one can start) and without spawning dedicated threads for them.

[go to top]