33 lines
696 B
Rust
Raw Normal View History

use lib_dispatch::prelude::*;
use lib_dispatch::runtime::AFPluginRuntime;
use std::sync::Arc;
use tokio::task::LocalSet;
2022-01-23 12:14:00 +08:00
pub async fn hello() -> String {
"say hello".to_string()
2022-01-23 12:14:00 +08:00
}
#[tokio::test]
2021-09-04 15:12:53 +08:00
async fn test() {
let event = "1";
let runtime = Arc::new(AFPluginRuntime::new().unwrap());
let dispatch = Arc::new(AFPluginDispatcher::new(
runtime,
vec![AFPlugin::new().event(event, hello)],
));
let request = AFPluginRequest::new(event);
let _ = AFPluginDispatcher::async_send_with_callback(
dispatch.as_ref(),
request,
|resp| {
Box::pin(async move {
dbg!(&resp);
})
},
&LocalSet::new(),
)
.await;
2021-09-04 15:12:53 +08:00
std::mem::forget(dispatch);
}