Pedagogical futures::join?

Is there any pedagogical impl of futures::join ?

I have looked at two impls so far, and they both end up using some pin_project macro.

Is there any minimal pedagogical example? Conceptually, I expect it to be rather simple:

if both futures are ready, be ready. If one is pending, stay pending.

Main tricky thing is that they might not become ready at the same time, and then you have to keep around the output of the one that completes first.

There's another implementation here. I made a version of it without pin-project here.

1 Like

Thanks @alice , this is really useful. One pedantic question: why is TryJoin3 not just calling Join3 and then processing after getting the 3 elements ?

Is the sole benefit here to "short circuit" optimization in that the moment one of the 3 gets Err, we stop polling the others ?

Yeah, this particular example is actually a try_join rather than a join, so it will immediately return if any one task returns error.

In your code above, is there any relation between Try and MaybeDone ? I.e. if you were implementing Join3 instead of Try_Join3, would you still use MaybeDone ?

Intuitively, the answer seems like yes, because it appears the main point of a MaybeDone is to give the option of either taking or not taking the answer.

Yes, the thing that makes you need MaybeDone is the join part. If only had the "try" part (i.e. a select), then you don't need MaybeDone.