28 lines
677 B
Rust
Raw Normal View History

2022-06-28 08:56:15 +08:00
use lib_dispatch::prelude::*;
use lib_dispatch::runtime::tokio_default_runtime;
2021-09-04 15:12:53 +08:00
use std::sync::Arc;
2022-01-23 12:14:00 +08:00
pub async fn hello() -> String {
"say hello".to_string()
}
#[tokio::test]
2021-09-04 15:12:53 +08:00
async fn test() {
2021-09-17 19:03:46 +08:00
env_logger::init();
let event = "1";
2022-01-23 22:33:47 +08:00
let runtime = tokio_default_runtime().unwrap();
let dispatch = Arc::new(EventDispatcher::construct(runtime, || {
vec![Module::new().event(event, hello)]
}));
let request = ModuleRequest::new(event);
2021-12-04 11:26:17 +08:00
let _ = EventDispatcher::async_send_with_callback(dispatch.clone(), request, |resp| {
Box::pin(async move {
dbg!(&resp);
})
})
.await;
2021-09-04 15:12:53 +08:00
std::mem::forget(dispatch);
}