Switch from Rc<RefCell> to Arc<Mutex<T>> or Arc<ReentrantMutex<RefCell<T>>>.

This commit is contained in:
Oleksandr Kozachuk
2023-01-06 13:12:58 +01:00
parent a2978c1230
commit 538a32a471
13 changed files with 384 additions and 214 deletions
+1
View File
@@ -13,6 +13,7 @@ crate-type = ["cdylib"]
[dependencies]
hel = { version = "0.1.0", path = "../hel" }
lazy_static = "1.4.0"
wasm-bindgen = "0.2.83"
[dependencies.web-sys]
+8 -2
View File
@@ -1,7 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<script type="module" src="./pkg/helwasm.js"></script>
<script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
@@ -76,7 +75,9 @@
</head>
<body>
<div id="root"></div>
<script type="text/javascript">
<script type="module">
import init, { ok_add } from "./pkg/helwasm.js";
function read_line(prompt) {
console.log("called read_line: " + prompt);
return "line";
@@ -87,6 +88,11 @@
return "password";
}
init().then(() => {
window.hel = {
ok_add: ok_add,
}
});
</script>
<script type="text/babel">
function Terminal() {
+6
View File
@@ -0,0 +1,6 @@
use hel::lk::LK;
use std::sync::{Arc, Mutex};
lazy_static! {
static ref STATE: Arc<Mutex<LK>> = Arc::new(Mutex::new(LK::new()));
}
+8
View File
@@ -1,3 +1,5 @@
#[macro_use]
extern crate lazy_static;
extern crate hel;
use wasm_bindgen::prelude::*;
@@ -6,3 +8,9 @@ use wasm_bindgen::prelude::*;
pub fn ok_add(a: i32, b: i32) -> i32 {
a + b + 1
}
mod hel_state;
#[wasm_bindgen]
pub fn hel_init() {
}