mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-01 18:01:06 +00:00
Fixing panic if the Future wakes up after returning Poll::Ready
This commit is contained in:
parent
9cac16f2d6
commit
5a1dfdf2ab
@ -233,27 +233,27 @@ where
|
|||||||
|
|
||||||
match lock.pop_front() {
|
match lock.pop_front() {
|
||||||
Some(task) => {
|
Some(task) => {
|
||||||
let mut future = task.future.borrow_mut();
|
let mut borrow = task.future.borrow_mut();
|
||||||
|
|
||||||
let poll = {
|
// This will only be None if the Future wakes up the Waker after returning Poll::Ready
|
||||||
// This will only panic if the Future wakes up the Waker after returning Poll::Ready
|
if let Some(future) = borrow.as_mut() {
|
||||||
let mut future = future.as_mut().unwrap_throw();
|
let poll = {
|
||||||
|
// Clear `is_queued` flag so that it will re-queue if poll calls waker.wake()
|
||||||
|
task.is_queued.set(false);
|
||||||
|
|
||||||
// Clear `is_queued` flag so that it will re-queue if poll calls waker.wake()
|
// This is necessary because the polled task might queue more tasks
|
||||||
task.is_queued.set(false);
|
drop(lock);
|
||||||
|
|
||||||
// This is necessary because the polled task might queue more tasks
|
// TODO is there some way of saving these so they don't need to be recreated all the time ?
|
||||||
drop(lock);
|
let waker = ArcWake::into_waker(task.clone());
|
||||||
|
let cx = &mut Context::from_waker(&waker);
|
||||||
|
Pin::new(future).poll(cx)
|
||||||
|
};
|
||||||
|
|
||||||
// TODO is there some way of saving these so they don't need to be recreated all the time ?
|
if let Poll::Ready(_) = poll {
|
||||||
let waker = ArcWake::into_waker(task.clone());
|
// Cleanup the Future immediately
|
||||||
let cx = &mut Context::from_waker(&waker);
|
*borrow = None;
|
||||||
Pin::new(&mut future).poll(cx)
|
}
|
||||||
};
|
|
||||||
|
|
||||||
if let Poll::Ready(_) = poll {
|
|
||||||
// Cleanup the Future immediately
|
|
||||||
*future = None;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user