bugfix: Fix wasm32 compile errors
Signed-off-by: John Nunley <dev@notgull.net>
This commit is contained in:
parent
f076528d27
commit
6c3d45b23c
|
@ -37,12 +37,14 @@ jobs:
|
|||
- uses: actions/checkout@v4
|
||||
- name: Install Rust
|
||||
run: rustup update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
|
||||
- run: rustup target add wasm32-unknown-unknown
|
||||
- run: cargo build --all --all-features --all-targets
|
||||
if: startsWith(matrix.rust, 'nightly')
|
||||
- name: Run cargo check (without dev-dependencies to catch missing feature flags)
|
||||
if: startsWith(matrix.rust, 'nightly')
|
||||
run: cargo check -Z features=dev_dep
|
||||
- run: cargo test
|
||||
- run: cargo check --all --all-features --target wasm32-unknown-unknown
|
||||
|
||||
msrv:
|
||||
runs-on: ubuntu-latest
|
||||
|
|
13
src/lib.rs
13
src/lib.rs
|
@ -270,7 +270,18 @@ impl<'a> Executor<'a> {
|
|||
|
||||
/// Returns a reference to the inner state.
|
||||
fn state(&self) -> &Arc<State> {
|
||||
self.state.get_or_init_blocking(|| Arc::new(State::new()))
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
{
|
||||
return self.state.get_or_init_blocking(|| Arc::new(State::new()));
|
||||
}
|
||||
|
||||
// Some projects use this on WASM for some reason. In this case get_or_init_blocking
|
||||
// doesn't work. Just poll the future once and panic if there is contention.
|
||||
#[cfg(target_family = "wasm")]
|
||||
future::block_on(future::poll_once(
|
||||
self.state.get_or_init(|| async { Arc::new(State::new()) }),
|
||||
))
|
||||
.expect("encountered contention on WASM")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue