Skip to content

Commit 6c3d45b

Browse files
authored
bugfix: Fix wasm32 compile errors
Signed-off-by: John Nunley <[email protected]>
1 parent f076528 commit 6c3d45b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ jobs:
3737
- uses: actions/checkout@v4
3838
- name: Install Rust
3939
run: rustup update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
40+
- run: rustup target add wasm32-unknown-unknown
4041
- run: cargo build --all --all-features --all-targets
4142
if: startsWith(matrix.rust, 'nightly')
4243
- name: Run cargo check (without dev-dependencies to catch missing feature flags)
4344
if: startsWith(matrix.rust, 'nightly')
4445
run: cargo check -Z features=dev_dep
4546
- run: cargo test
47+
- run: cargo check --all --all-features --target wasm32-unknown-unknown
4648

4749
msrv:
4850
runs-on: ubuntu-latest

src/lib.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,18 @@ impl<'a> Executor<'a> {
270270

271271
/// Returns a reference to the inner state.
272272
fn state(&self) -> &Arc<State> {
273-
self.state.get_or_init_blocking(|| Arc::new(State::new()))
273+
#[cfg(not(target_family = "wasm"))]
274+
{
275+
return self.state.get_or_init_blocking(|| Arc::new(State::new()));
276+
}
277+
278+
// Some projects use this on WASM for some reason. In this case get_or_init_blocking
279+
// doesn't work. Just poll the future once and panic if there is contention.
280+
#[cfg(target_family = "wasm")]
281+
future::block_on(future::poll_once(
282+
self.state.get_or_init(|| async { Arc::new(State::new()) }),
283+
))
284+
.expect("encountered contention on WASM")
274285
}
275286
}
276287

0 commit comments

Comments
 (0)