mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
rename flowy-dispatch structs
This commit is contained in:
@ -11,13 +11,13 @@ use futures_util::task::Context;
|
||||
use pin_project::pin_project;
|
||||
use std::{future::Future, sync::Arc};
|
||||
use tokio::macros::support::{Pin, Poll};
|
||||
pub struct EventDispatch {
|
||||
pub struct EventDispatcher {
|
||||
module_map: ModuleMap,
|
||||
runtime: tokio::runtime::Runtime,
|
||||
}
|
||||
|
||||
impl EventDispatch {
|
||||
pub fn construct<F>(module_factory: F) -> EventDispatch
|
||||
impl EventDispatcher {
|
||||
pub fn construct<F>(module_factory: F) -> EventDispatcher
|
||||
where
|
||||
F: FnOnce() -> Vec<Module>,
|
||||
{
|
||||
@ -26,18 +26,18 @@ impl EventDispatch {
|
||||
tracing::trace!("{}", module_info(&modules));
|
||||
let module_map = as_module_map(modules);
|
||||
|
||||
EventDispatch { module_map, runtime }
|
||||
EventDispatcher { module_map, runtime }
|
||||
}
|
||||
|
||||
pub fn async_send<Req>(dispatch: Arc<EventDispatch>, request: Req) -> DispatchFuture<EventResponse>
|
||||
pub fn async_send<Req>(dispatch: Arc<EventDispatcher>, request: Req) -> DispatchFuture<EventResponse>
|
||||
where
|
||||
Req: std::convert::Into<ModuleRequest>,
|
||||
{
|
||||
EventDispatch::async_send_with_callback(dispatch, request, |_| Box::pin(async {}))
|
||||
EventDispatcher::async_send_with_callback(dispatch, request, |_| Box::pin(async {}))
|
||||
}
|
||||
|
||||
pub fn async_send_with_callback<Req, Callback>(
|
||||
dispatch: Arc<EventDispatch>,
|
||||
dispatch: Arc<EventDispatcher>,
|
||||
request: Req,
|
||||
callback: Callback,
|
||||
) -> DispatchFuture<EventResponse>
|
||||
@ -70,9 +70,9 @@ impl EventDispatch {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sync_send(dispatch: Arc<EventDispatch>, request: ModuleRequest) -> EventResponse {
|
||||
pub fn sync_send(dispatch: Arc<EventDispatcher>, request: ModuleRequest) -> EventResponse {
|
||||
futures::executor::block_on(async {
|
||||
EventDispatch::async_send_with_callback(dispatch, request, |_| Box::pin(async {})).await
|
||||
EventDispatcher::async_send_with_callback(dispatch, request, |_| Box::pin(async {})).await
|
||||
})
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ mod util;
|
||||
|
||||
mod byte_trait;
|
||||
mod data;
|
||||
mod dispatch;
|
||||
mod dispatcher;
|
||||
mod system;
|
||||
|
||||
#[macro_use]
|
||||
@ -16,5 +16,5 @@ pub mod macros;
|
||||
pub use errors::Error;
|
||||
|
||||
pub mod prelude {
|
||||
pub use crate::{byte_trait::*, data::*, dispatch::*, errors::*, module::*, request::*, response::*};
|
||||
pub use crate::{byte_trait::*, data::*, dispatcher::*, errors::*, module::*, request::*, response::*};
|
||||
}
|
||||
|
@ -8,9 +8,9 @@ async fn test() {
|
||||
env_logger::init();
|
||||
|
||||
let event = "1";
|
||||
let dispatch = Arc::new(EventDispatch::construct(|| vec![Module::new().event(event, hello)]));
|
||||
let dispatch = Arc::new(EventDispatcher::construct(|| vec![Module::new().event(event, hello)]));
|
||||
let request = ModuleRequest::new(event);
|
||||
let _ = EventDispatch::async_send_with_callback(dispatch.clone(), request, |resp| {
|
||||
let _ = EventDispatcher::async_send_with_callback(dispatch.clone(), request, |resp| {
|
||||
Box::pin(async move {
|
||||
dbg!(&resp);
|
||||
})
|
||||
|
Reference in New Issue
Block a user