@@ -45,25 +45,29 @@ where
4545 fn poll_next ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Option < Self :: Item > > {
4646 let this = self . project ( ) ;
4747 if utils:: random ( 1 ) == 1 {
48- match this. left . poll_next ( cx) {
49- Poll :: Ready ( Some ( item) ) => Poll :: Ready ( Some ( item) ) ,
50- Poll :: Ready ( None ) => this. right . poll_next ( cx) ,
51- Poll :: Pending => match this. right . poll_next ( cx) {
52- Poll :: Ready ( Some ( item) ) => Poll :: Ready ( Some ( item) ) ,
53- Poll :: Ready ( None ) => Poll :: Pending ,
54- Poll :: Pending => Poll :: Pending ,
55- } ,
56- }
48+ poll_next_in_order ( this. left , this. right , cx)
5749 } else {
58- match this. right . poll_next ( cx) {
59- Poll :: Ready ( Some ( item) ) => Poll :: Ready ( Some ( item) ) ,
60- Poll :: Ready ( None ) => this. left . poll_next ( cx) ,
61- Poll :: Pending => match this. left . poll_next ( cx) {
62- Poll :: Ready ( Some ( item) ) => Poll :: Ready ( Some ( item) ) ,
63- Poll :: Ready ( None ) => Poll :: Pending ,
64- Poll :: Pending => Poll :: Pending ,
65- } ,
66- }
50+ poll_next_in_order ( this. right , this. left , cx)
6751 }
6852 }
6953}
54+
55+ fn poll_next_in_order < F , S , I > (
56+ first : Pin < & mut F > ,
57+ second : Pin < & mut S > ,
58+ cx : & mut Context < ' _ > ,
59+ ) -> Poll < Option < I > >
60+ where
61+ F : Stream < Item = I > ,
62+ S : Stream < Item = I > ,
63+ {
64+ match first. poll_next ( cx) {
65+ Poll :: Ready ( Some ( item) ) => Poll :: Ready ( Some ( item) ) ,
66+ Poll :: Ready ( None ) => second. poll_next ( cx) ,
67+ Poll :: Pending => match second. poll_next ( cx) {
68+ Poll :: Ready ( Some ( item) ) => Poll :: Ready ( Some ( item) ) ,
69+ Poll :: Ready ( None ) => Poll :: Pending ,
70+ Poll :: Pending => Poll :: Pending ,
71+ } ,
72+ }
73+ }
0 commit comments