Skip to content

Commit

Permalink
Merge pull request #463 from poborin/fix/rinf_wasm_binding
Browse files Browse the repository at this point in the history
log an error if the binding is not ready
  • Loading branch information
temeddix authored Oct 23, 2024
2 parents 05c7647 + 37cbda4 commit 033e80e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions rust_crate/src/interface_web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,28 @@ where

#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = rinf)]
#[wasm_bindgen(js_namespace = rinf, catch)]
pub fn send_rust_signal_extern(
resource: i32,
message_bytes: Uint8Array,
binary: Uint8Array,
);
) -> Result<(), JsValue>; // catch the JS exception
}

pub fn send_rust_signal_real(
message_id: i32,
message_bytes: Vec<u8>,
binary: Vec<u8>,
) -> Result<(), RinfError> {
send_rust_signal_extern(
match send_rust_signal_extern(
message_id,
js_sys::Uint8Array::from(message_bytes.as_slice()),
js_sys::Uint8Array::from(binary.as_slice()),
);
Ok(())
) {
Ok(_) => Ok(()),
Err(e) => {
crate::debug_print!("An error occured during the launch: {e:?}");
Err(RinfError::NoSignalHandler)
}
}
}

0 comments on commit 033e80e

Please sign in to comment.