What would you expect this program to print?
Conversation
Notices
-
Embed this notice
Eric Holk (theincredibleholk@mastodon.social)'s status on Friday, 08-Dec-2023 09:58:18 JST Eric Holk
-
Embed this notice
esmevane, sorry (ironchamber@mastodon.esmevane.com)'s status on Friday, 08-Dec-2023 09:58:17 JST esmevane, sorry
@theincredibleholk When I look at this, I think of it as a single async context, so because it hasn't been awaited, it hasn't been polled, and so that first yield still hasn't been materialized. So I think about it like this:
1. We get a yield future. We don't await it.
2. We get that same yield future again, and await it. The future materializes.So I guess in that world, if you then await first, either:
1. It gets the next value / None.
2. It's considered invalid/semi-dropped. Panic? -
Embed this notice
esmevane, sorry (ironchamber@mastodon.esmevane.com)'s status on Friday, 08-Dec-2023 10:30:33 JST esmevane, sorry
@theincredibleholk (I wrote all this without checking at all, because I thought we were supposed to explain what we imagined would happen. Seems like that was a miss on my part whoops/oof)
-
Embed this notice
esmevane, sorry (ironchamber@mastodon.esmevane.com)'s status on Saturday, 09-Dec-2023 03:37:35 JST esmevane, sorry
@theincredibleholk Whew! haha. Thanks for saying so.
fwiw I think 2 feels less surprising to me. 1 could lead to really unexpected behavior, and that'd be bad. It'd be even better if there were redlines in my editor telling me I goofed up, before I get to a panic, but I'd rather predictable explosions than hard to track bugs.
-
Embed this notice
Eric Holk (theincredibleholk@mastodon.social)'s status on Saturday, 09-Dec-2023 03:37:36 JST Eric Holk
@ironchamber That's actually good you didn't check it. Mostly I wanted to get a sense of what people's intuition was, like what they expected it to do.
I realized after I put the poll up I could just drop this in the Rust Playground and find out what happens, but "what happens today?" is a different question from "what should happen?"
I think your option 2 is closest to what actually happens if we made this program a little more realistic.
-
Embed this notice