You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to propose a variant on select, perhaps called first or race (the latter copied from javascript). Unlike select, it would simply discard other results from incomplete futures. This allows it to have a much simpler implementation, and to allow non-unpin futures. It'd look like this:
#![derive(Debug,Clone,Default)]structFirst<A,B>{future1:A,future2:B}impl<A:Future,B:Future>FutureforSelect<A,B>{typeOutput = Either<A::Output,B::Output>;fnpoll(self:Poll<&mutSelf>,cx:&mutContext) -> Poll<Self::Output>{// This will obviously have to use a pin projectionmatchself.future1.poll(cx) => {Poll::Ready(a) => Poll::Ready(Either::Left(a)),Poll::Pending => self.future2.map(|b| Either::Right(b)).poll(cx),}}}impl<A:FusedFuture,B:FusedFuture>FusedFutureforSelect<A,B>{fnis_terminated(&self) -> bool{self.first.is_terminated() || self.second.is_terminated()}}
The use case here would be for combining with more ephemeral futures, such as timeouts, or any other case where you only care about the first completed future, rather than trying to track and preserve the set of futures being selected over.
The text was updated successfully, but these errors were encountered:
I'd like to propose a variant on
select
, perhaps calledfirst
orrace
(the latter copied from javascript). Unlikeselect
, it would simply discard other results from incomplete futures. This allows it to have a much simpler implementation, and to allow non-unpin
futures. It'd look like this:The use case here would be for combining with more ephemeral futures, such as timeouts, or any other case where you only care about the first completed future, rather than trying to track and preserve the set of futures being selected over.
The text was updated successfully, but these errors were encountered: