Skip to content

Make sure promise polls spawner #312

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 17 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ members = [
[workspace.dependencies]
rquickjs-core = { version = "0.8.1", path = "core" }
rquickjs-macro = { version = "0.8.1", path = "macro" }
rquickjs-sys= { version = "0.8.1", path = "sys" }
rquickjs-sys = { version = "0.8.1", path = "sys" }
rquickjs = { version = "0.8.1", path = "./" }

[dependencies]
Expand All @@ -35,12 +35,23 @@ rquickjs-core = { workspace = true }
rquickjs-macro = { workspace = true, optional = true }



[features]
default = ["classes", "properties"]

# Almost all features excluding "parallel" and support for async runtimes
full = ["chrono", "loader", "allocator", "dyn-load", "either", "indexmap", "classes", "properties", "array-buffer", "macro", "phf"]
full = [
"chrono",
"loader",
"allocator",
"dyn-load",
"either",
"indexmap",
"classes",
"properties",
"array-buffer",
"macro",
"phf",
]

# Almost all features excluding "parallel"
full-async = ["full", "futures"]
Expand Down Expand Up @@ -93,6 +104,9 @@ macro = ["rquickjs-macro"]
# Disabled for now as it can be used to create unsound code.
# multi-ctx = ["rquickjs-core/multi-ctx"]

# Enable promises to advance tasks spawned in the scheduler via ctx.spawn
promise_poll_spawner = ["rquickjs-core/promise_poll_spawner"]

# Enable interop between Rust futures and JS Promises
futures = ["rquickjs-core/futures"]

Expand Down Expand Up @@ -122,4 +136,3 @@ trybuild = "1.0.82"

[package.metadata.docs.rs]
features = ["full-async", "parallel", "doc-cfg"]

28 changes: 22 additions & 6 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ relative-path = { version = "1.9", optional = true }


[dev-dependencies]
futures-rs = { package = "futures", version = "0.3"}
tokio = { version = "1.0", default-features = false, features = ["rt", "rt-multi-thread", "time", "macros", "sync"] }
futures-rs = { package = "futures", version = "0.3" }
tokio = { version = "1.0", default-features = false, features = [
"rt",
"rt-multi-thread",
"time",
"macros",
"sync",
] }
rquickjs = { workspace = true }
approx = "0.5"
trybuild = "1.0.23"
Expand All @@ -35,7 +41,17 @@ trybuild = "1.0.23"
default = []

# Almost all features excluding "parallel" and support for async runtimes
full = ["chrono", "loader", "allocator", "dyn-load", "either", "indexmap", "classes", "properties", "array-buffer"]
full = [
"chrono",
"loader",
"allocator",
"dyn-load",
"either",
"indexmap",
"classes",
"properties",
"array-buffer",
]

# Almost all features excluding "parallel"
full-async = ["full", "futures"]
Expand Down Expand Up @@ -75,6 +91,9 @@ futures = ["dep:async-lock"]
# Allows transferring objects between different contexts of the same runtime.
multi-ctx = []

# Poll spawner from promise
promise_poll_spawner = []

# Enable QuickJS dumps for debug
dump-bytecode = ["rquickjs-sys/dump-bytecode"]
dump-gc = ["rquickjs-sys/dump-gc"]
Expand All @@ -95,6 +114,3 @@ compile-tests = []

# Enable unstable doc-cfg feature (for docs.rs)
doc-cfg = []



9 changes: 9 additions & 0 deletions core/src/value/promise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ where
return Poll::Ready(x);
}

#[cfg(feature = "promise_poll_spawner")]
{
let opaque: &mut crate::runtime::opaque::Opaque = unsafe {
let rt = qjs::JS_GetRuntime(this.promise.ctx.as_ptr());
&mut *(qjs::JS_GetRuntimeOpaque(rt) as *mut _)
};
opaque.poll(cx);
}

if this.state.is_none() {
let inner = Rc::new(RefCell::new(cx.waker().clone()));
this.state = Some(inner.clone());
Expand Down