1
1
#![ allow( dead_code) ]
2
2
3
3
use std:: {
4
- mem :: transmute ,
4
+ marker :: PhantomPinned ,
5
5
sync:: Arc ,
6
6
task:: { ready, Poll } ,
7
7
} ;
@@ -99,9 +99,10 @@ impl RequestScope {
99
99
RequestScopeGuard {
100
100
cancelled : false ,
101
101
req_end_tx : self . req_end_tx . clone ( ) ,
102
- termination_token : self . termination_token . clone ( ) ,
102
+ termination_token : Some ( self . termination_token . clone ( ) ) ,
103
103
conn_tx : self . conn . 0 . take ( ) . unwrap ( ) ,
104
104
inner : None ,
105
+ _pinned : PhantomPinned ,
105
106
}
106
107
}
107
108
}
@@ -110,9 +111,10 @@ impl RequestScope {
110
111
pub struct RequestScopeGuard {
111
112
cancelled : bool ,
112
113
req_end_tx : mpsc:: UnboundedSender < ( ) > ,
113
- termination_token : TerminationToken ,
114
+ termination_token : Option < TerminationToken > ,
114
115
conn_tx : watch:: Sender < ConnSync > ,
115
116
inner : Option < BoxFuture < ' static , ( ) > > ,
117
+ _pinned : PhantomPinned ,
116
118
}
117
119
118
120
impl Future for RequestScopeGuard {
@@ -127,11 +129,11 @@ impl Future for RequestScopeGuard {
127
129
if !( * this. cancelled ) {
128
130
* this. cancelled = true ;
129
131
this. req_end_tx . send ( ( ) ) . unwrap ( ) ;
130
- this. termination_token . inbound . cancel ( ) ;
132
+ this. termination_token . as_ref ( ) . unwrap ( ) . inbound . cancel ( ) ;
131
133
}
132
134
133
- let inner = this. inner . get_or_insert_with ( || unsafe {
134
- transmute ( this. termination_token . outbound . cancelled ( ) . boxed ( ) )
135
+ let inner = this. inner . get_or_insert_with ( || {
136
+ wait_termination ( this. termination_token . take ( ) . unwrap ( ) ) . boxed ( )
135
137
} ) ;
136
138
137
139
ready ! ( inner. as_mut( ) . poll_unpin( cx) ) ;
@@ -165,3 +167,7 @@ pub fn test_user_runtime_opts() -> UserWorkerRuntimeOpts {
165
167
..Default :: default ( )
166
168
}
167
169
}
170
+
171
+ async fn wait_termination ( token : TerminationToken ) {
172
+ token. outbound . cancelled ( ) . await ;
173
+ }
0 commit comments