4 ms·
> you can't use regular if/while/for with async What do you mean by this? You can certainly mix if/while/for freely with .await, that's the whole reason it exi
by Rusky 3y ago
> you can't use regular if/while/for with async
What do you mean by this? You can certainly mix if/while/for freely with .await, that's the whole reason it exists.
- bobbylarrybobby 3y agoI believe the distinction is that in rust, `if a_cond.await` can only be written in an async function, whereas Haskell’s `ifM` takes a `Monad Bool` (and async is a kind of monad) as its condition and therefore can be written anywhere, not just within an existing monad.
- Rusky 3y agoThat's a distinction without a difference. `ifM` takes a monadic bool but it also returns a monadic value, in exactly the same way that `.await` can only be done within an async computation.
- lmm 3y agoSorry, yes, what I meant was you can use builtin if/while/for, but they're magic special cases that you can't reuse. E.g. if you have a repeated snippet of code that uses if/while/for, you might have exactly the same code in one async and one regular function, but you can't factor it out into a shared helper function (you can write the async and the non-async version of that helper function, but you can't write one that does both).