Skip to content

Commit

Permalink
fix reset! lock usage; add event-entry arg; bump 0.3.16
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed May 15, 2021
1 parent 8ebd67c commit acfe65a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "calcit_runner"
version = "0.3.15"
version = "0.3.16"
authors = ["jiyinyiyong <[email protected]>"]
edition = "2018"
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@calcit/procs",
"version": "0.3.15",
"version": "0.3.16",
"main": "./lib/calcit.procs.js",
"devDependencies": {
"@types/node": "^15.0.1",
Expand Down
17 changes: 8 additions & 9 deletions src/builtins/refs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,22 @@ lazy_static! {
}

// need functions with shorter lifetime to escape dead lock
fn read_ref(path: &str) -> Option<Calcit> {
fn read_ref(path: &str) -> Option<ValueAndListeners> {
let dict = &REFS_DICT.lock().unwrap();
match dict.get(path) {
Some((v, _)) => Some(v.to_owned()),
Some(pair) => Some(pair.to_owned()),
None => None,
}
}

fn write_to_ref(path: String, v: Calcit) {
fn write_to_ref(path: String, v: Calcit, listeners: HashMap<String, Calcit>) {
let dict = &mut REFS_DICT.lock().unwrap();
let _ = dict.insert(path, (v, HashMap::new()));
let _ = dict.insert(path, (v, listeners));
}

fn modify_ref(path: String, v: Calcit, program_code: &ProgramCodeData) -> Result<(), String> {
let dict = &mut REFS_DICT.lock().unwrap();
let (prev, listeners) = &dict.get(&path).unwrap().clone();
let _ = dict.insert(path, (v.to_owned(), listeners.to_owned()));
let (prev, listeners) = read_ref(&path).unwrap();
write_to_ref(path, v.to_owned(), listeners.to_owned());

for f in listeners.values() {
match f {
Expand Down Expand Up @@ -59,7 +58,7 @@ pub fn defatom(

if read_ref(&path).is_none() {
let v = runner::evaluate_expr(code, scope, file_ns, program_code)?;
write_to_ref(path.to_owned(), v)
write_to_ref(path.to_owned(), v, HashMap::new())
}
Ok(Calcit::Ref(path))
}
Expand All @@ -71,7 +70,7 @@ pub fn defatom(
pub fn deref(xs: &CalcitItems) -> Result<Calcit, String> {
match xs.get(0) {
Some(Calcit::Ref(path)) => match read_ref(path) {
Some(v) => Ok(v),
Some((v, _)) => Ok(v),
None => Err(format!("found nothing after refer &{}", path)),
},
Some(a) => Err(format!("deref expected a ref, got: {}", a)),
Expand Down
7 changes: 7 additions & 0 deletions src/cli_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ pub fn parse_cli<'a>() -> clap::ArgMatches<'a> {
.long("reload-fn")
.takes_value(true),
)
.arg(
clap::Arg::with_name("event-entry")
.help("entry ns/def for handling events")
.long("event-entry")
.default_value("app.main/on-window-event")
.takes_value(true),
)
.arg(
clap::Arg::with_name("reload-libs")
.help("reload libs data during code reload")
Expand Down

0 comments on commit acfe65a

Please sign in to comment.