AppFlowy/frontend/rust-lib/lib-dispatch/tests/api/module.rs
Nathan.fooo 6d09c33782
chore: spawn task on local set (#6012)
* chore: spawn local

* chore: using multiple thread runtime

* chore: fix test
2024-08-20 14:16:24 +08:00

34 lines
745 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 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;
std::mem::forget(dispatch);
}