AppFlowy/frontend/rust-lib/lib-dispatch/tests/api/module.rs
Nathan.fooo e08a1a6974
feat: enable dispatch event using single thread (#3828)
* refactor: lib dispatch

* chore: type def

* chore: type def

* fix: local set spawn

* chore: replace tokio spawn

* chore: update log

* chore: boxed event

* chore: tauri lock
2023-10-30 12:35:06 +08:00

27 lines
628 B
Rust

use std::sync::Arc;
use lib_dispatch::prelude::*;
use lib_dispatch::runtime::AFPluginRuntime;
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::construct(runtime, || {
vec![AFPlugin::new().event(event, hello)]
}));
let request = AFPluginRequest::new(event);
let _ = AFPluginDispatcher::async_send_with_callback(dispatch.clone(), request, |resp| {
Box::pin(async move {
dbg!(&resp);
})
})
.await;
std::mem::forget(dispatch);
}