@@ -233,27 +233,27 @@ where
233
233
234
234
match lock. pop_front( ) {
235
235
Some ( task) => {
236
- let mut future = task. future. borrow_mut( ) ;
237
-
238
- let poll = {
239
- // This will only panic if the Future wakes up the Waker after returning Poll::Ready
240
- let mut future = future . as_mut ( ) . unwrap_throw ( ) ;
241
-
242
- // Clear `is_queued` flag so that it will re-queue if poll calls waker.wake()
243
- task . is_queued . set ( false ) ;
244
-
245
- // This is necessary because the polled task might queue more tasks
246
- drop ( lock ) ;
247
-
248
- // TODO is there some way of saving these so they don't need to be recreated all the time ?
249
- let waker = ArcWake :: into_waker ( task . clone ( ) ) ;
250
- let cx = & mut Context :: from_waker ( & waker ) ;
251
- Pin :: new ( & mut future ) . poll ( cx )
252
- } ;
253
-
254
- if let Poll :: Ready ( _ ) = poll {
255
- // Cleanup the Future immediately
256
- * future = None ;
236
+ let mut borrow = task. future. borrow_mut( ) ;
237
+
238
+ // This will only be None if the Future wakes up the Waker after returning Poll::Ready
239
+ if let Some ( future ) = borrow . as_mut ( ) {
240
+ let poll = {
241
+ // Clear `is_queued` flag so that it will re-queue if poll calls waker.wake()
242
+ task . is_queued . set ( false ) ;
243
+
244
+ // This is necessary because the polled task might queue more tasks
245
+ drop ( lock ) ;
246
+
247
+ // TODO is there some way of saving these so they don't need to be recreated all the time ?
248
+ let waker = ArcWake :: into_waker ( task . clone ( ) ) ;
249
+ let cx = & mut Context :: from_waker ( & waker ) ;
250
+ Pin :: new ( future ) . poll ( cx )
251
+ } ;
252
+
253
+ if let Poll :: Ready ( _ ) = poll {
254
+ // Cleanup the Future immediately
255
+ * borrow = None ;
256
+ }
257
257
}
258
258
} ,
259
259
None => {
0 commit comments