A final proposal for await syntax

In C#, I yesterday (literally -- I just checked) gave the "you should do that in parallel" feedback for this code (domain object names obfuscated, but the code is otherwise untouched):

var sprockets = await this.ExtractContent<SprocketContent>(SprocketPath);
var widgets = await this.ExtractContent<WidgetContent>(WidgetPath);
var spanners = await this.ExtractContent<SpannerContent>(SpannerPath);

So I think prefix await isn't immune to "just await without thinking about it" either.

That said, it's a pain in C# to do this differently, because Task.WhenAll only supports the homogeneous case. If I understand How will Promise.all be implemented? - #4 by Matthias247 correctly, then this will be way better in Rust -- whether prefix or postfix -- as it could be

let (sprockets, widgets, spanners) = join!(
    self.extract_content::<SprocketContent>(SPROCKET_PATH),
    self.extract_content::<WidgetContent>(WIDGET_PATH),
    self.extract_content::<SpannerContent>(SPANNER_PATH),
).await;

+1, and I wonder if that actually makes .await less noticeable than with no highlighting, as one's brain starts relying on the colours for mental parsing shortcuts.

11 Likes