v0.2.7-pre.010
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-onchain-transport-lib/src/ws_session.rs
|
||||
// version: 10
|
||||
// version: 11
|
||||
|
||||
use futures_util::SinkExt; // rust-rules: trait-import
|
||||
use futures_util::StreamExt; // rust-rules: trait-import
|
||||
@@ -167,11 +167,27 @@ impl WsSession {
|
||||
where
|
||||
T: std::marker::Send + 'static,
|
||||
F: Fn(serde_json::Value) -> ksp_core_lib::Result<T> + std::marker::Send + std::marker::Sync + 'static,
|
||||
{
|
||||
return self.subscribe_typed_with_completion(kind, params, decoder, |_| return false).await;
|
||||
}
|
||||
|
||||
/// Creates one crate-internal typed subscription whose decoder can identify a delivered terminal notification.
|
||||
pub(crate) async fn subscribe_typed_with_completion<T, F, C>(
|
||||
&self,
|
||||
kind: crate::WsSubscriptionKind,
|
||||
params: std::vec::Vec<serde_json::Value>,
|
||||
decoder: F,
|
||||
is_terminal: C,
|
||||
) -> ksp_core_lib::Result<crate::WsSubscription<T>>
|
||||
where
|
||||
T: std::marker::Send + 'static,
|
||||
F: Fn(serde_json::Value) -> ksp_core_lib::Result<T> + std::marker::Send + std::marker::Sync + 'static,
|
||||
C: Fn(&T) -> bool + std::marker::Send + std::marker::Sync + 'static,
|
||||
{
|
||||
if self.state() != crate::WsSessionState::Active {
|
||||
return std::result::Result::Err(ws_session_closed_error(self.id, "WebSocket session is not active"));
|
||||
}
|
||||
let (dispatcher, notification_rx) = crate::typed_notification_channel(self.notification_queue_capacity, decoder);
|
||||
let (dispatcher, notification_rx) = crate::typed_notification_channel_with_completion(self.notification_queue_capacity, decoder, is_terminal);
|
||||
let (response_tx, response_rx) = tokio::sync::oneshot::channel();
|
||||
let command = WsSessionCommand::Subscribe { kind, params, dispatcher, response_tx };
|
||||
let send_wait = tokio::time::timeout(self.command_timeout, self.command_tx.send(command)).await;
|
||||
@@ -1901,6 +1917,17 @@ fn handle_subscription_notification(
|
||||
let dispatch = (runtime.dispatcher)(result);
|
||||
return match dispatch {
|
||||
crate::WsNotificationDispatchOutcome::Delivered => WsActorIoOutcome::Continue,
|
||||
crate::WsNotificationDispatchOutcome::DeliveredTerminal => {
|
||||
close_local_subscription(subscriptions, remote_to_local, local_id, crate::WsSubscriptionState::Closed);
|
||||
ksp_logging_lib::debug!(
|
||||
target: crate::TRACING_TARGET,
|
||||
session_id = id.get(),
|
||||
subscription_id = local_id.get(),
|
||||
subscription_kind = subscription_kind.as_str(),
|
||||
"logical WebSocket subscription observed its server-terminal notification"
|
||||
);
|
||||
WsActorIoOutcome::Continue
|
||||
},
|
||||
crate::WsNotificationDispatchOutcome::ReceiverClosed => {
|
||||
close_local_subscription(subscriptions, remote_to_local, local_id, crate::WsSubscriptionState::Closed);
|
||||
ksp_logging_lib::debug!(
|
||||
|
||||
Reference in New Issue
Block a user