Skip to content

Commit ea9afea

Browse files
committed
try lazylock; tag 0.2.6
1 parent e55c4a8 commit ea9afea

File tree

6 files changed

+39
-18
lines changed

6 files changed

+39
-18
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@
1212
.compact-inc.cirru
1313

1414
/dylibs/
15+
16+
.DS_Store

Cargo.lock

Lines changed: 30 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "calcit_wss"
3-
version = "0.2.5"
3+
version = "0.2.6"
44
authors = ["jiyinyiyong <[email protected]>"]
55
edition = "2021"
66

@@ -13,6 +13,5 @@ crate-type = ["dylib"] # Creates dynamic lib
1313
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1414

1515
[dependencies]
16-
cirru_edn = "0.6.5"
17-
lazy_static = "1.4.0"
16+
cirru_edn = "0.6.12"
1817
simple-websockets = "0.1.6"

calcit.cirru

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compact.cirru

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
{} (:package |wss)
3-
:configs $ {} (:init-fn |wss.test/main!) (:reload-fn |wss.test/reload!) (:version |0.2.5)
3+
:configs $ {} (:init-fn |wss.test/main!) (:reload-fn |wss.test/reload!) (:version |0.2.6)
44
:modules $ []
55
:entries $ {}
66
:demo $ {} (:init-fn |wss.test/demo!) (:port 6001) (:reload-fn |wss.test/reload!)

src/lib.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
use cirru_edn::{Edn, EdnTupleView};
2-
use lazy_static::lazy_static;
32
use simple_websockets::{Event, Message, Responder};
43
use std::collections::HashMap;
5-
use std::sync::{Arc, RwLock};
4+
use std::sync::{Arc, LazyLock, RwLock};
65
use std::thread::spawn;
76

8-
lazy_static! {
9-
static ref CLIENTS: RwLock<HashMap<u64, Responder>> = RwLock::new(HashMap::new());
10-
}
7+
static CLIENTS: LazyLock<RwLock<HashMap<u64, Responder>>> = LazyLock::new(|| RwLock::new(HashMap::new()));
118

129
#[no_mangle]
1310
pub fn abi_version() -> String {
@@ -100,7 +97,7 @@ pub fn wss_send(args: Vec<Edn>) -> Result<Edn, String> {
10097
let clients = CLIENTS.read().unwrap();
10198
let responder = clients.get(&(*id as u64)).unwrap();
10299
// echo the message back:
103-
responder.send(Message::Text(s.to_string().to_owned()));
100+
responder.send(Message::Text(s.to_string()));
104101
Ok(Edn::Nil)
105102
}
106103
(a, b) => Err(format!("wss-send expected id and message, got {} {}", a, b)),

0 commit comments

Comments
 (0)