module_event.rs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. use crate::helper::*;
  2. use flowy_sys::prelude::*;
  3. pub async fn no_params() -> String { "no params function call".to_string() }
  4. pub async fn one_params(_s: String) -> String { "one params function call".to_string() }
  5. pub async fn two_params(_s1: String, _s2: String) -> String { "two params function call".to_string() }
  6. #[test]
  7. fn test() {
  8. setup_env();
  9. let no_params_command = "no params".to_string();
  10. let one_params_command = "one params".to_string();
  11. let two_params_command = "two params".to_string();
  12. let stream = CommandStream::<i64>::new();
  13. let tx = stream.tx();
  14. FlowySystem::construct(
  15. || {
  16. vec![Module::new()
  17. .event(no_params_command.clone(), no_params)
  18. .event(one_params_command.clone(), one_params)
  19. .event(two_params_command.clone(), two_params)]
  20. },
  21. stream,
  22. )
  23. .spawn(async move {
  24. let request = EventRequest::new(no_params_command.clone());
  25. let stream_data = StreamData::new(
  26. 1,
  27. Some(request),
  28. Box::new(|config, response| {
  29. log::info!("{:?}", response);
  30. }),
  31. );
  32. tx.send(stream_data);
  33. FlowySystem::current().stop();
  34. })
  35. .run()
  36. .unwrap();
  37. }