Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: borrow_mut error in future.rs #14

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "deno_unsync"
version = "0.3.5"
version = "0.3.6"
edition = "2021"
authors = ["the Deno authors"]
license = "MIT"
Expand Down
22 changes: 12 additions & 10 deletions src/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,10 @@ where
let mut inner = self.0.data.borrow_mut();
match &mut inner.future_or_output {
FutureOrOutput::Future(fut) => {
self
.0
.child_waker_state
.wakers
.borrow_mut()
.push(cx.waker().clone());
{
let mut wakers = self.0.child_waker_state.wakers.borrow_mut();
wakers.push(cx.waker().clone());
}
if self.0.child_waker_state.can_poll.lower() {
let child_waker =
create_child_waker(self.0.child_waker_state.clone());
Expand All @@ -141,9 +139,10 @@ where
Poll::Ready(result) => {
inner.future_or_output = FutureOrOutput::Output(result.clone());
drop(inner); // stop borrow_mut
let wakers = std::mem::take(
&mut *self.0.child_waker_state.wakers.borrow_mut(),
);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe this one is the one that caused the issue? I just changed them all to use blocks to be sure because I always get bitten by this.

let wakers = {
let mut wakers = self.0.child_waker_state.wakers.borrow_mut();
std::mem::take(&mut *wakers)
};
for waker in wakers {
waker.wake();
}
Expand Down Expand Up @@ -207,7 +206,10 @@ unsafe fn wake_waker(data: *const ()) {
unsafe fn wake_by_ref_waker(data: *const ()) {
let state = Rc::from_raw(data as *const ChildWakerState);
state.can_poll.raise();
let wakers = state.wakers.borrow().clone();
let wakers = {
let wakers = state.wakers.borrow();
wakers.clone()
};
for waker in wakers {
waker.wake_by_ref();
}
Expand Down