Skip to content

Commit

Permalink
Avoid leaving a dangling future when handling a rejection in JsPromis…
Browse files Browse the repository at this point in the history
…e::to_future
  • Loading branch information
kjvalencik committed Nov 27, 2023
1 parent cd740c9 commit f8cedab
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions crates/neon/src/types_impl/promise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ impl JsPromise {
+ 'static,
{
let then = self.get::<JsFunction, _, _>(cx, "then")?;
let catch = self.get::<JsFunction, _, _>(cx, "catch")?;

let (tx, rx) = oneshot::channel();
let take_state = {
Expand Down Expand Up @@ -235,8 +234,11 @@ impl JsPromise {
}
})?;

then.exec(cx, Handle::new_internal(Self(self.0)), [resolve.upcast()])?;
catch.exec(cx, Handle::new_internal(Self(self.0)), [reject.upcast()])?;
then.exec(
cx,
Handle::new_internal(Self(self.0)),
[resolve.upcast(), reject.upcast()],
)?;

Ok(JsFuture { rx })
}
Expand Down

0 comments on commit f8cedab

Please sign in to comment.