workflow_rpc/client/protocol/
mod.rs1mod borsh;
2mod serde_json;
3#[allow(unused_imports)]
4pub use crate::client::error::Error;
5pub use crate::client::result::Result;
6use crate::imports::*;
7
8pub use self::borsh::BorshProtocol;
9pub use self::serde_json::JsonProtocol;
10use crate::client::Interface;
11
12#[async_trait]
13pub trait ProtocolHandler<Ops>: DowncastSync
14where
15 Ops: OpsT,
16{
17 fn new(ws: Arc<WebSocket>, interface: Option<Arc<Interface<Ops>>>) -> Self
18 where
19 Self: Sized;
20 async fn handle_timeout(&self, timeout: Duration);
21 async fn handle_message(&self, message: WebSocketMessage) -> Result<()>;
22 async fn handle_disconnect(&self) -> Result<()>;
23 }
25impl_downcast!(sync ProtocolHandler<Ops> where Ops: OpsT);
26
27struct Pending<F> {
28 timestamp: Instant,
29 callback: F,
30}
31impl<F> Pending<F> {
32 fn new(callback: F) -> Self {
33 Self {
34 timestamp: Instant::now(),
35 callback,
36 }
37 }
38}
39
40type PendingMap<Id, F> = Arc<Mutex<AHashMap<Id, Pending<F>>>>;