2023-10-30 04:35:06 +00:00
|
|
|
use lib_dispatch::prelude::*;
|
|
|
|
use lib_dispatch::runtime::AFPluginRuntime;
|
2024-08-19 14:08:10 +00:00
|
|
|
use std::sync::Arc;
|
|
|
|
use tokio::task::LocalSet;
|
2023-10-30 04:35:06 +00:00
|
|
|
|
2022-01-23 04:14:00 +00:00
|
|
|
pub async fn hello() -> String {
|
2023-02-13 01:29:49 +00:00
|
|
|
"say hello".to_string()
|
2022-01-23 04:14:00 +00:00
|
|
|
}
|
2021-06-29 08:52:29 +00:00
|
|
|
|
2021-07-02 12:45:51 +00:00
|
|
|
#[tokio::test]
|
2021-09-04 07:12:53 +00:00
|
|
|
async fn test() {
|
2023-02-13 01:29:49 +00:00
|
|
|
let event = "1";
|
2024-08-19 14:08:10 +00:00
|
|
|
let runtime = Arc::new(AFPluginRuntime::new().unwrap());
|
2024-08-20 09:07:54 +00:00
|
|
|
#[allow(clippy::arc_with_non_send_sync)]
|
2024-08-19 14:08:10 +00:00
|
|
|
let dispatch = Arc::new(AFPluginDispatcher::new(
|
2024-01-05 16:37:26 +00:00
|
|
|
runtime,
|
|
|
|
vec![AFPlugin::new().event(event, hello)],
|
|
|
|
));
|
2023-02-13 01:29:49 +00:00
|
|
|
let request = AFPluginRequest::new(event);
|
2024-08-20 06:16:24 +00:00
|
|
|
let local_set = LocalSet::new();
|
|
|
|
local_set
|
|
|
|
.run_until(AFPluginDispatcher::async_send_with_callback(
|
|
|
|
dispatch.as_ref(),
|
|
|
|
request,
|
|
|
|
|resp| {
|
|
|
|
Box::pin(async move {
|
|
|
|
dbg!(&resp);
|
|
|
|
})
|
|
|
|
},
|
|
|
|
))
|
|
|
|
.await;
|
2021-09-04 07:12:53 +00:00
|
|
|
|
2023-02-13 01:29:49 +00:00
|
|
|
std::mem::forget(dispatch);
|
2021-06-29 08:52:29 +00:00
|
|
|
}
|