-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Separate Yew Platform #2893
Separate Yew Platform #2893
Changes from 7 commits
6992ada
ae41979
efb5ae4
e6c7e1e
7c91aff
eac2f19
f62a737
95509cc
9b03269
680590b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,14 +25,21 @@ slab = "0.4" | |
wasm-bindgen = "0.2" | ||
yew-macro = { version = "^0.19.0", path = "../yew-macro" } | ||
thiserror = "1.0" | ||
futures = { version = "0.3", default-features = false, features = ["std", "async-await"] } | ||
futures = { version = "0.3", default-features = false, features = ["std"] } | ||
html-escape = { version = "0.2.9", optional = true } | ||
implicit-clone = { version = "0.3", features = ["map"] } | ||
base64ct = { version = "1.5.0", features = ["std"], optional = true } | ||
bincode = { version = "1.3.3", optional = true } | ||
serde = { version = "1", features = ["derive"] } | ||
tracing = "0.1.36" | ||
pin-project = "1.0.11" | ||
prokio = "0.1.0" | ||
|
||
[target.'cfg(target_arch = "wasm32")'.dependencies] | ||
wasm-bindgen-futures = "0.4" | ||
Comment on lines
+38
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we still need a direct dependency on this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is due to yew is using wasm_bindgen_futures::JsFuture in a couple places. |
||
|
||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] | ||
# We still need tokio as we have docs linked to it. | ||
tokio = { version = "1.19", features = ["rt"] } | ||
|
||
[dependencies.web-sys] | ||
version = "^0.3.59" | ||
|
@@ -69,21 +76,12 @@ features = [ | |
"SubmitEvent" | ||
] | ||
|
||
[target.'cfg(target_arch = "wasm32")'.dependencies] | ||
# we move it here so no promise-based spawn_local can present for | ||
# non-wasm32 targets. | ||
wasm-bindgen-futures = "0.4" | ||
|
||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] | ||
num_cpus = { version = "1.13", optional = true } | ||
once_cell = "1" | ||
tokio = { version = "1.21.1", features = ["rt", "time"], optional = true } | ||
tokio-stream = { version = "0.1", features = ["time"], optional = true } | ||
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] | ||
tokio = { version = "1.19", features = ["full"] } | ||
|
||
[dev-dependencies] | ||
wasm-bindgen-test = "0.3" | ||
gloo = { version = "0.8", features = ["futures"] } | ||
wasm-bindgen-futures = "0.4" | ||
rustversion = "1" | ||
trybuild = "1" | ||
|
||
|
@@ -95,15 +93,11 @@ features = [ | |
] | ||
|
||
[features] | ||
tokio = ["dep:tokio", "dep:num_cpus", "dep:tokio-stream"] | ||
ssr = ["dep:html-escape", "dep:base64ct", "dep:bincode"] | ||
csr = [] | ||
hydration = ["csr", "dep:bincode"] | ||
default = [] | ||
|
||
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] | ||
tokio = { version = "1.19", features = ["full"] } | ||
|
||
[package.metadata.docs.rs] | ||
all-features = true | ||
rustdoc-args = ["--cfg", "documenting"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,6 @@ | |
//! - `csr`: Enables Client-side Rendering support and [`Renderer`]. Only enable this feature if you | ||
//! are making a Yew application (not a library). | ||
//! - `ssr`: Enables Server-side Rendering support and [`ServerRenderer`]. | ||
//! - `tokio`: Enables future-based APIs on non-wasm32 targets with tokio runtime. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both Hence, I feel it might be better to forego the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this this way. Tokio is hidden behind the pseudo-runtime (prokio) and doesn't need to be exposed here. |
||
//! - `hydration`: Enables Hydration support. | ||
//! | ||
//! ## Example | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//! Yew's compatibility between JavaScript Runtime and Native Runtimes. | ||
//! | ||
//! This module is also published under the name [prokio](crate@prokio) on crates.io. | ||
//! | ||
//! # Rationale | ||
//! | ||
//! When designing components and libraries that works on both WebAssembly targets backed by | ||
//! JavaScript Runtime and non-WebAssembly targets with Native Runtimes. Developers usually face | ||
//! challenges that requires applying multiple feature flags throughout their application: | ||
//! | ||
//! 1. Select I/O and timers that works with the target runtime. | ||
//! 2. Native Runtimes usually require `Send` futures and WebAssembly types are usually `!Send`. | ||
//! | ||
//! # Implementation | ||
//! | ||
//! To alleviate these issues, Yew implements a single-threaded runtime that executes `?Send` | ||
//! (`Send` or `!Send`) futures. | ||
//! | ||
//! On platforms with multi-threading support, Yew spawns multiple independent runtimes | ||
//! proportional to the CPU core number. When tasks are spawned with a runtime handle, it will | ||
//! randomly select a worker thread from the internal pool. All tasks spawned with `spawn_local` | ||
//! will run on the same thread as the thread the task was running. When the runtime runs in a | ||
//! WebAssembly target, all tasks will be scheduled on the main thread. | ||
//! | ||
//! This runtime is designed in favour of IO-bounded workload with similar runtime cost. | ||
//! When running I/O workloads, it would produce a slightly better performance as tasks are | ||
//! never moved to another thread. However, If a worker thread is busy, | ||
//! other threads will not be able to steal tasks scheduled on the busy thread. | ||
//! When you have a CPU-bounded task where CPU time is significantly | ||
//! more expensive, it should be spawned with a dedicated thread (or Web Worker) and communicates | ||
//! with the application using channels. | ||
//! | ||
//! Yew platform provides the following components: | ||
//! | ||
//! 1. A Task Scheduler that is capable of running non-Send tasks. | ||
//! 2. A Timer that is compatible with the scheduler backend. | ||
//! 3. Task Synchronisation Mechanisms. | ||
//! | ||
//! # Runtime Backend | ||
//! | ||
//! The Yew runtime is implemented with different runtimes depending on the target platform and can | ||
//! use all features (timers / IO / task synchronisation) from the selected native runtime: | ||
//! | ||
//! - `wasm-bindgen-futures` (WebAssembly targets) | ||
//! - `tokio` (non-WebAssembly targets) | ||
|
||
#[doc(inline)] | ||
pub use prokio::*; | ||
Comment on lines
+47
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can put this in lib.rs to have the same effect: #[doc(inline)]
pub use prokio as platform; That way you can avoid duplicating the doc comments. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is intentional. The documentation of yew::platform and prokio is slightly different. The wording is adjusted to mention Yew in the documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume they move to prokio, correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is removed completely and does not present in prokio as well. As previously mentioned, the tokio feature is not very useful. I expect the current situation to stay years before it changes. So I guess it might be better to remove tokio feature and read it when we need it.