sciter-sdk / rust-sciter

Rust bindings for Sciter
https://sciter.com
MIT License
804 stars 76 forks source link

add Send & Sync marker trait to Element #18

Closed WLBF closed 6 years ago

WLBF commented 6 years ago

It seems like send and share Element between threads and call its api from different thread is fine. add Send and Sync to Element will allow code like:

impl EventHandler {
    fn Download(&self, root: Element) -> Option<Value> {
        thread::spawn(move || {
            ...
            let _ = root.call_function("onSuccess", &make_args!());
        });
        None
    }
}

impl sciter::EventHandler for EventHandler {

    fn attached(&mut self, root: HELEMENT) {
        self.root = Some(Element::from(root));
    }

    fn on_script_call(&mut self, root: HELEMENT, name: &str, argv: &[Value]) -> Option<Value> {
        match name {
            "Download" => self.Download(Element::from(root)),
            _ => None,
        }
    }
}

It's much easier to write worker thread. Above code works fine on my simple project, but I haven't test other api. How should I test all those api? any suggestion?

pravic commented 6 years ago

Great, thanks. I'll test it against the debug Sciter to ensure that everything is okay.

pravic commented 6 years ago

Yeah, that's it. Thanks.