module_event.rs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 runner = FlowySystem::construct(|| {
  13. vec![Module::new()
  14. .event(no_params_command.clone(), no_params)
  15. .event(one_params_command.clone(), one_params)
  16. .event(two_params_command.clone(), two_params)]
  17. });
  18. let stream = CommandStream::new(FlowySystem::current().module_map());
  19. let tx = stream.data_tx.clone();
  20. runner
  21. .spawn(stream)
  22. .spawn(async move {
  23. let request = EventRequest::new(no_params_command.clone());
  24. let stream_data = StreamData::new(
  25. 1,
  26. Some(request),
  27. Box::new(|config, response| {
  28. log::info!("{:?}", response);
  29. }),
  30. );
  31. tx.send(stream_data);
  32. FlowySystem::current().stop();
  33. })
  34. .run()
  35. .unwrap();
  36. }