module.rs 677 B

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