module.rs 624 B

12345678910111213141516171819202122232425
  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. let event = "1";
  10. let runtime = tokio_default_runtime().unwrap();
  11. let dispatch = Arc::new(AFPluginDispatcher::construct(runtime, || {
  12. vec![AFPlugin::new().event(event, hello)]
  13. }));
  14. let request = AFPluginRequest::new(event);
  15. let _ = AFPluginDispatcher::async_send_with_callback(dispatch.clone(), request, |resp| {
  16. Box::pin(async move {
  17. dbg!(&resp);
  18. })
  19. })
  20. .await;
  21. std::mem::forget(dispatch);
  22. }