module.rs 654 B

123456789101112131415161718192021222324
  1. use lib_dispatch::{prelude::*, util::tokio_default_runtime};
  2. use std::sync::Arc;
  3. pub async fn hello() -> String { "say hello".to_string() }
  4. #[tokio::test]
  5. async fn test() {
  6. env_logger::init();
  7. let event = "1";
  8. let runtime = tokio_default_runtime().unwrap();
  9. let dispatch = Arc::new(EventDispatcher::construct(runtime, || {
  10. vec![Module::new().event(event, hello)]
  11. }));
  12. let request = ModuleRequest::new(event);
  13. let _ = EventDispatcher::async_send_with_callback(dispatch.clone(), request, |resp| {
  14. Box::pin(async move {
  15. dbg!(&resp);
  16. })
  17. })
  18. .await;
  19. std::mem::forget(dispatch);
  20. }