@@ -23,10 +23,11 @@ pin_project! {
2323 #[ derive( Clone ) ]
2424 #[ allow( missing_docs) ]
2525 pub struct ScopedFuture <Fut > {
26- pub owner: Owner ,
27- pub observer: Option <AnySubscriber >,
26+ owner: Owner ,
27+ observer: Option <AnySubscriber >,
28+ diagnostics: bool ,
2829 #[ pin]
29- pub fut: Fut ,
30+ fut: Fut ,
3031 }
3132}
3233
@@ -39,61 +40,53 @@ impl<Fut> ScopedFuture<Fut> {
3940 Self {
4041 owner,
4142 observer,
43+ diagnostics : true ,
4244 fut,
4345 }
4446 }
4547
46- #[ doc( hidden) ]
47- #[ track_caller]
48- pub fn new_untracked_with_diagnostics ( fut : Fut ) -> Self {
48+ /// Wraps the given `Future` by taking the current [`Owner`] re-setting it as the
49+ /// active owner every time the inner `Future` is polled. Always untracks, i.e., clears
50+ /// the active [`Observer`] when polled.
51+ pub fn new_untracked ( fut : Fut ) -> Self {
4952 let owner = Owner :: current ( ) . unwrap_or_default ( ) ;
5053 Self {
5154 owner,
5255 observer : None ,
56+ diagnostics : false ,
5357 fut,
5458 }
5559 }
56- }
57-
58- impl < Fut : Future > Future for ScopedFuture < Fut > {
59- type Output = Fut :: Output ;
60-
61- fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
62- let this = self . project ( ) ;
63- this. owner
64- . with ( || this. observer . with_observer ( || this. fut . poll ( cx) ) )
65- }
66- }
6760
68- pin_project ! {
6961 #[ doc( hidden) ]
70- pub struct __NonReactiveZoneFut<Fut > {
71- #[ pin]
72- fut: Fut ,
73- }
74- }
75-
76- impl < Fut > ScopedFuture < __NonReactiveZoneFut < Fut > > {
77- /// Wraps the given `Future` by taking the current [`Owner`] re-setting it as the
78- /// active owner every time the inner `Future` is polled. Always untracks, i.e., clears
79- /// the active [`Observer`] when polled.
80- pub fn new_untracked ( fut : Fut ) -> Self {
62+ #[ track_caller]
63+ pub fn new_untracked_with_diagnostics ( fut : Fut ) -> Self {
8164 let owner = Owner :: current ( ) . unwrap_or_default ( ) ;
8265 Self {
8366 owner,
8467 observer : None ,
85- fut : __NonReactiveZoneFut { fut } ,
68+ diagnostics : true ,
69+ fut,
8670 }
8771 }
8872}
8973
90- impl < Fut : Future > Future for __NonReactiveZoneFut < Fut > {
74+ impl < Fut : Future > Future for ScopedFuture < Fut > {
9175 type Output = Fut :: Output ;
9276
9377 fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
94- #[ cfg( debug_assertions) ]
95- let _guard = crate :: diagnostics:: SpecialNonReactiveZone :: enter ( ) ;
96- self . project ( ) . fut . poll ( cx)
78+ let this = self . project ( ) ;
79+ this. owner . with ( || {
80+ this. observer . with_observer ( || {
81+ #[ cfg( debug_assertions) ]
82+ let _maybe_guard = if * this. diagnostics {
83+ None
84+ } else {
85+ Some ( crate :: diagnostics:: SpecialNonReactiveZone :: enter ( ) )
86+ } ;
87+ this. fut . poll ( cx)
88+ } )
89+ } )
9790 }
9891}
9992
0 commit comments