2021-06-28 15:58:43 +00:00
|
|
|
use flowy_sys::prelude::*;
|
|
|
|
use std::cell::RefCell;
|
2021-06-28 14:56:15 +00:00
|
|
|
|
2021-06-28 15:58:43 +00:00
|
|
|
pub struct FlowySDK {}
|
|
|
|
|
|
|
|
impl FlowySDK {
|
|
|
|
pub fn init(path: &str) {
|
|
|
|
let modules = init_modules();
|
|
|
|
init_system(modules);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn init_modules() -> Vec<Module> {
|
|
|
|
let modules = vec![];
|
|
|
|
modules
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn init_system<F>(modules: Vec<Module>) {
|
|
|
|
FlowySystem::construct(
|
|
|
|
|| modules,
|
2021-06-30 07:33:49 +00:00
|
|
|
|module_map, runtime| {
|
|
|
|
let mut sender = Sender::<i64>::new(module_map.clone());
|
|
|
|
runtime.spawn(SenderRunner::new(module_map, sender.take_rx()));
|
2021-06-28 15:58:43 +00:00
|
|
|
|
2021-06-30 07:33:49 +00:00
|
|
|
SENDER.with(|cell| {
|
|
|
|
*cell.borrow_mut() = Some(sender);
|
2021-06-28 15:58:43 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.run()
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
thread_local!(
|
2021-06-30 07:33:49 +00:00
|
|
|
static SENDER: RefCell<Option<Sender<i64>>> = RefCell::new(None);
|
2021-06-28 15:58:43 +00:00
|
|
|
);
|
|
|
|
|
2021-06-30 07:33:49 +00:00
|
|
|
pub fn sync_send(data: SenderData<i64>) -> EventResponse {
|
|
|
|
SENDER.with(|cell| match &*cell.borrow() {
|
2021-06-28 15:58:43 +00:00
|
|
|
Some(stream) => stream.sync_send(data),
|
|
|
|
None => panic!(""),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-06-30 07:33:49 +00:00
|
|
|
pub fn async_send(data: SenderData<i64>) {
|
|
|
|
SENDER.with(|cell| match &*cell.borrow() {
|
2021-06-28 15:58:43 +00:00
|
|
|
Some(stream) => {
|
|
|
|
stream.async_send(data);
|
|
|
|
},
|
|
|
|
None => panic!(""),
|
|
|
|
});
|
|
|
|
}
|