Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add capacity and max_capacity to the subscription API #1414

Merged
merged 8 commits into from
Jun 20, 2024
Merged
10 changes: 10 additions & 0 deletions core/src/server/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ impl MethodSink {
self.tx.send_timeout(msg, timeout).await.map_err(Into::into)
}

/// Get the capacity of the channel.
niklasad1 marked this conversation as resolved.
Show resolved Hide resolved
pub fn capacity(&self) -> usize {
self.tx.capacity()
}

/// Get the max capacity of the channel.
pub fn max_capacity(&self) -> usize {
self.tx.max_capacity()
}

/// Waits for there to be space on the return channel.
pub async fn has_capacity(&self) -> Result<(), DisconnectError> {
match self.tx.reserve().await {
Expand Down
20 changes: 20 additions & 0 deletions core/src/server/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,16 @@ impl PendingSubscriptionSink {
self.uniq_sub.conn_id
}

/// Get the capacity of the channel.
pub fn capacity(&self) -> usize {
self.inner.capacity()
}

/// Get the max capacity of the channel.
pub fn max_capacity(&self) -> usize {
self.inner.max_capacity()
}

/// Get the method name.
pub fn method_name(&self) -> &str {
self.method
Expand Down Expand Up @@ -406,6 +416,16 @@ impl SubscriptionSink {
}
}

/// Get the capacity of the subscription sink.
niklasad1 marked this conversation as resolved.
Show resolved Hide resolved
pub fn capacity(&self) -> usize {
self.inner.capacity()
}

/// Get the max capacity of the subscription.
pub fn max_capacity(&self) -> usize {
self.inner.max_capacity()
}

fn is_active_subscription(&self) -> bool {
!self.unsubscribe.is_unsubscribed()
}
Expand Down
Loading