File tree Expand file tree Collapse file tree 1 file changed +19
-4
lines changed Expand file tree Collapse file tree 1 file changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -464,10 +464,25 @@ impl<T> Future for UnwrapToPending<T> {
464464}
465465
466466pub ( crate ) async fn race2 < T , A : Future < Output = T > , B : Future < Output = T > > ( f1 : A , f2 : B ) -> T {
467- tokio:: select! {
468- x = f1 => x,
469- x = f2 => x,
470- }
467+ // Pin the futures on the stack for polling
468+ let mut f1 = std:: pin:: pin!( f1) ;
469+ let mut f2 = std:: pin:: pin!( f2) ;
470+
471+ // Create a future that resolves when either f1 or f2 completes
472+ std:: future:: poll_fn ( |cx| {
473+ // Poll both futures
474+ match f1. as_mut ( ) . poll ( cx) {
475+ Poll :: Ready ( result) => return Poll :: Ready ( result) ,
476+ Poll :: Pending => { }
477+ }
478+ match f2. as_mut ( ) . poll ( cx) {
479+ Poll :: Ready ( result) => return Poll :: Ready ( result) ,
480+ Poll :: Pending => { }
481+ }
482+ // If neither is ready, yield back to the executor
483+ Poll :: Pending
484+ } )
485+ . await
471486}
472487
473488/// Run a server loop, invoking a handler callback for each request.
You can’t perform that action at this time.
0 commit comments