lib.rs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. use flowy_sys::prelude::*;
  2. use std::cell::RefCell;
  3. pub struct FlowySDK {}
  4. impl FlowySDK {
  5. pub fn init(path: &str) {
  6. let modules = init_modules();
  7. init_system(modules);
  8. }
  9. }
  10. pub fn init_modules() -> Vec<Module> {
  11. let modules = vec![];
  12. modules
  13. }
  14. pub fn init_system<F>(modules: Vec<Module>) {
  15. FlowySystem::construct(
  16. || modules,
  17. |module_map| {
  18. let mut stream = CommandSender::<i64>::new(module_map.clone());
  19. let runner = CommandSenderRunner::new(module_map, stream.take_data_rx());
  20. CMD_SENDER.with(|cell| {
  21. *cell.borrow_mut() = Some(stream);
  22. });
  23. runner
  24. },
  25. )
  26. .run()
  27. .unwrap();
  28. }
  29. thread_local!(
  30. static CMD_SENDER: RefCell<Option<CommandSender<i64>>> = RefCell::new(None);
  31. );
  32. pub fn sync_send(data: CommandData<i64>) -> EventResponse {
  33. CMD_SENDER.with(|cell| match &*cell.borrow() {
  34. Some(stream) => stream.sync_send(data),
  35. None => panic!(""),
  36. })
  37. }
  38. pub fn async_send(data: CommandData<i64>) {
  39. CMD_SENDER.with(|cell| match &*cell.borrow() {
  40. Some(stream) => {
  41. stream.async_send(data);
  42. },
  43. None => panic!(""),
  44. });
  45. }