Consult modules
This commit is contained in:
23
src/wasm.rs
23
src/wasm.rs
@@ -38,8 +38,7 @@ pub struct WasmMachine {
|
|||||||
|
|
||||||
#[wasm_bindgen(js_class = Machine)]
|
#[wasm_bindgen(js_class = Machine)]
|
||||||
impl WasmMachine {
|
impl WasmMachine {
|
||||||
#[wasm_bindgen(js_name = runQuery)]
|
fn ensure_machine_ownership(&mut self) -> Result<(), JsValue> {
|
||||||
pub fn run_query(&mut self, query: String) -> Result<JsValue, JsValue> {
|
|
||||||
if self.inner.is_err() {
|
if self.inner.is_err() {
|
||||||
// We have a receiver, try to get the Machine
|
// We have a receiver, try to get the Machine
|
||||||
let machine = self
|
let machine = self
|
||||||
@@ -50,7 +49,12 @@ impl WasmMachine {
|
|||||||
.map_err(|_| js_sys::Error::new("Another query is still active"))?;
|
.map_err(|_| js_sys::Error::new("Another query is still active"))?;
|
||||||
let _ = mem::replace(&mut self.inner, Ok(machine));
|
let _ = mem::replace(&mut self.inner, Ok(machine));
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen(js_name = runQuery)]
|
||||||
|
pub fn run_query(&mut self, query: String) -> Result<JsValue, JsValue> {
|
||||||
|
self.ensure_machine_ownership()?;
|
||||||
assert!(self.inner.is_ok());
|
assert!(self.inner.is_ok());
|
||||||
|
|
||||||
// Installs a receiver and gets the machine
|
// Installs a receiver and gets the machine
|
||||||
@@ -71,6 +75,21 @@ impl WasmMachine {
|
|||||||
|
|
||||||
Ok(query_state)
|
Ok(query_state)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen(js_name = consultModuleString)]
|
||||||
|
pub fn consult_module_string(
|
||||||
|
&mut self,
|
||||||
|
module: String,
|
||||||
|
program: String,
|
||||||
|
) -> Result<(), JsValue> {
|
||||||
|
self.ensure_machine_ownership()?;
|
||||||
|
assert!(self.inner.is_ok());
|
||||||
|
|
||||||
|
let inner = self.inner.as_mut().unwrap();
|
||||||
|
inner.consult_module_string(&module, program);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[self_referencing]
|
#[self_referencing]
|
||||||
|
|||||||
Reference in New Issue
Block a user