Files
archived-smoke-tests/packages/create-react-app/lib/rust/src/lib.rs
Lucas Fernandes Nogueira b3d831ac25 chore(merge) feature/event-system (#12)
* feat(event-system) prototype

* feat(event-system) prepare two way communication

* feat(event-system) fASLR

* feat(event-system) answer salt

* feat(event-system) simplify communication and enable multi-level two way message passing
2020-02-09 16:47:40 -05:00

61 lines
1.2 KiB
Rust

#[macro_use]
extern crate serde_derive;
#[macro_use]
mod macros;
#[macro_use]
extern crate lazy_static;
pub mod api;
pub mod command;
pub mod dir;
pub mod event;
pub mod file;
pub mod file_system;
pub mod http;
pub mod platform;
pub mod process;
pub mod rpc;
pub mod salt;
pub mod tcp;
pub mod updater;
pub mod version;
use proton_ui::WebView;
use threadpool::ThreadPool;
thread_local!(static POOL: ThreadPool = ThreadPool::new(4));
pub fn spawn<F: FnOnce() -> () + Send + 'static>(what: F) {
POOL.with(|thread| {
thread.execute(move || {
what();
});
});
}
pub fn run_async<F: FnOnce() -> () + Send + 'static>(what: F) {
POOL.with(|thread| {
thread.execute(move || what());
});
}
pub fn execute_promise<T: 'static, F: FnOnce() -> Result<String, String> + Send + 'static>(
webview: &mut WebView<'_, T>,
what: F,
callback: String,
error: String,
) {
let handle = webview.handle();
POOL.with(|thread| {
thread.execute(move || {
let callback_string = rpc::format_callback_result(what(), callback, error);
handle
.dispatch(move |_webview| _webview.eval(callback_string.as_str()))
.unwrap()
});
});
}