AppFlowy/frontend/rust-lib/lib-dispatch/tests/api/module.rs
Nathan.fooo 58b17a939c
chore: fix lib dispatch (#6008)
* chore: replace rc with arc

* chore: fix dispatch

* chore: fix test

* chore: fix dispatch

* chore: fix test

* chore: remove afconcurrent

* chore: fix runtime block_on runtime
2024-08-19 22:08:10 +08:00

33 lines
696 B
Rust

use lib_dispatch::prelude::*;
use lib_dispatch::runtime::AFPluginRuntime;
use std::sync::Arc;
use tokio::task::LocalSet;
pub async fn hello() -> String {
"say hello".to_string()
}
#[tokio::test]
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;
std::mem::forget(dispatch);
}