diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 66f75cf..a1b1af2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/src/lib.rs b/src/lib.rs index 79428cd..2411fb1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -263,7 +263,18 @@ impl<'a> Executor<'a> { /// Returns a reference to the inner state. fn state(&self) -> &Arc { - 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") } }