I haven’t had this much trouble since Ada coding in 1986 when I was age 16.
Can someone please help me get the procedural syntax right?
https://github.com/LemmyNet/lemmy/pull/3805

I haven’t had this much trouble since Ada coding in 1986 when I was age 16.
Can someone please help me get the procedural syntax right?
https://github.com/LemmyNet/lemmy/pull/3805

Taking a quick look at the changes, most of the changed code is in a block, not a function. I know the argument to
Box::pinlooks like a function, but it’s actually an async block. So you don’t have a function to return from.An anonymous function is introduced with an argument list surrounded by pipe characters (
|) which you don’t have here. OTOH a block is introduced with curly braces. It is very common to use a block as the body of an anonymous function so it’s easy to mix those up.A block introduces a new variable scope. It can have keyword modifiers,
asyncandmove, as you have here. The entire block is a value which is determined by the last expression in the block.That’s a long way of saying: delete the
returnkeyword, and remove the semicolon from the same line. That makes the value you want the last expression in theifbody, which makes that become the value of theifexpression, which then becomes the value of the block.ahh, I tried removing the return, but forgot the original .await line had no semicolon… Thank you!
Also worth mentioning, but you can early-return from a block in rust too, just using the
breakkeyword and named blocks:let x = 'my_block { if thing() { break 'my_block 1; } 2 };Edit: I haven’t tried this with
asyncblocks, but I’m guessing it works there too?Flow control like return and break work differently in async blocks. They are much closer to closures than blocks in this regard. And need to be as they are lazily evaluated (like closures) and may even be evaluated well after the code that contains them has finished.
Looks like labels don’t work on
asyncblocks, but using a nested inner block does work. Also, yeah,asyncblocks only exist to createFutures, they don’t execute until you start polling them. I don’t really see any reason why you couldn’t stick a label on the async block itself though, breaking would at worst just create one new state for the future - early returned.