Skip to content

Commit

Permalink
fix wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
vemonet committed Nov 17, 2023
1 parent 3c214d9 commit 2feca44
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/src/publish.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_futures::{spawn_local, wasm_bindgen};

// Blocking API not available on wasm, we need to use async with wasm_bindgen_futures

#[cfg(not(target_arch = "wasm32"))]
pub fn publish_np(url: &str, np: &str) -> bool {
let url = url.to_string();
Expand All @@ -14,13 +21,12 @@ pub fn publish_np(url: &str, np: &str) -> bool {
}

#[cfg(target_arch = "wasm32")]
#[wasm_bindgen_futures::wasm_bindgen]
#[wasm_bindgen]
pub fn publish_np(url: &str, np: &str) -> bool {
use wasm_bindgen::prelude::*;
let url = url.to_string();
let np = np.to_string();
let mut published: bool = false;
wasm_bindgen_futures::spawn_local(async move {
spawn_local(async move {
let client = reqwest::Client::new();
let res = client
.post(url)
Expand Down

0 comments on commit 2feca44

Please sign in to comment.