-
Notifications
You must be signed in to change notification settings - Fork 13
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: seaprate blocking methods #72
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,21 +142,13 @@ impl Client { | |
/// when fully processed by the relay. | ||
/// Note: This function is experimental and will likely be removed in the | ||
/// future. | ||
pub async fn subscribe_blocking(&self, topic: Topic) -> Response<rpc::Subscribe> { | ||
self.request(rpc::Subscribe { topic, block: true }).await | ||
pub async fn subscribe_blocking(&self, topic: Topic) -> Response<rpc::SubscribeBlocking> { | ||
self.request(rpc::SubscribeBlocking { topic }).await | ||
} | ||
|
||
/// Unsubscribes from a topic. | ||
pub async fn unsubscribe( | ||
&self, | ||
topic: Topic, | ||
subscription_id: SubscriptionId, | ||
) -> Response<rpc::Unsubscribe> { | ||
self.request(rpc::Unsubscribe { | ||
topic, | ||
subscription_id, | ||
}) | ||
.await | ||
pub async fn unsubscribe(&self, topic: Topic) -> Response<rpc::Unsubscribe> { | ||
self.request(rpc::Unsubscribe { topic }).await | ||
} | ||
|
||
/// Fetch mailbox messages for a specific topic. | ||
|
@@ -265,12 +257,18 @@ impl Client { | |
pub async fn batch_subscribe_blocking( | ||
&self, | ||
topics: impl Into<Vec<Topic>>, | ||
) -> Response<rpc::BatchSubscribe> { | ||
self.request(rpc::BatchSubscribe { | ||
topics: topics.into(), | ||
block: true, | ||
}) | ||
.await | ||
) -> Result< | ||
Vec<Result<SubscriptionId, Error<rpc::SubscriptionError>>>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess doesn't hurt to have in the future if needed |
||
Error<rpc::SubscriptionError>, | ||
> { | ||
Ok(self | ||
.request(rpc::BatchSubscribeBlocking { | ||
topics: topics.into(), | ||
}) | ||
.await? | ||
.into_iter() | ||
.map(crate::convert_subscription_result) | ||
.collect()) | ||
} | ||
|
||
/// Unsubscribes from multiple topics. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,28 @@ | ||
use { | ||
self::connection::{connection_event_loop, ConnectionControl}, | ||
crate::{error::ClientError, ConnectionOptions}, | ||
crate::{ | ||
error::{ClientError, Error}, | ||
ConnectionOptions, | ||
}, | ||
relay_rpc::{ | ||
domain::{MessageId, SubscriptionId, Topic}, | ||
rpc::{ | ||
BatchFetchMessages, | ||
BatchReceiveMessages, | ||
BatchSubscribe, | ||
BatchSubscribeBlocking, | ||
BatchUnsubscribe, | ||
FetchMessages, | ||
Publish, | ||
Receipt, | ||
Subscribe, | ||
SubscribeBlocking, | ||
Subscription, | ||
SubscriptionError, | ||
Unsubscribe, | ||
}, | ||
}, | ||
std::{sync::Arc, time::Duration}, | ||
std::{future::Future, sync::Arc, time::Duration}, | ||
tokio::sync::{ | ||
mpsc::{self, UnboundedSender}, | ||
oneshot, | ||
|
@@ -182,24 +188,17 @@ impl Client { | |
/// when fully processed by the relay. | ||
/// Note: This function is experimental and will likely be removed in the | ||
/// future. | ||
pub fn subscribe_blocking(&self, topic: Topic) -> ResponseFuture<Subscribe> { | ||
let (request, response) = create_request(Subscribe { topic, block: true }); | ||
pub fn subscribe_blocking(&self, topic: Topic) -> ResponseFuture<SubscribeBlocking> { | ||
let (request, response) = create_request(SubscribeBlocking { topic }); | ||
|
||
self.request(request); | ||
|
||
response | ||
} | ||
|
||
/// Unsubscribes from a topic. | ||
pub fn unsubscribe( | ||
&self, | ||
topic: Topic, | ||
subscription_id: SubscriptionId, | ||
) -> EmptyResponseFuture<Unsubscribe> { | ||
let (request, response) = create_request(Unsubscribe { | ||
topic, | ||
subscription_id, | ||
}); | ||
pub fn unsubscribe(&self, topic: Topic) -> EmptyResponseFuture<Unsubscribe> { | ||
let (request, response) = create_request(Unsubscribe { topic }); | ||
|
||
self.request(request); | ||
|
||
|
@@ -240,15 +239,25 @@ impl Client { | |
pub fn batch_subscribe_blocking( | ||
&self, | ||
topics: impl Into<Vec<Topic>>, | ||
) -> ResponseFuture<BatchSubscribe> { | ||
let (request, response) = create_request(BatchSubscribe { | ||
) -> impl Future< | ||
Output = Result< | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A bit ugly, I would use a type alias for this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why isn't the function just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making the function |
||
Vec<Result<SubscriptionId, Error<SubscriptionError>>>, | ||
Error<SubscriptionError>, | ||
>, | ||
> { | ||
let (request, response) = create_request(BatchSubscribeBlocking { | ||
topics: topics.into(), | ||
block: true, | ||
}); | ||
|
||
self.request(request); | ||
|
||
response | ||
async move { | ||
Ok(response | ||
.await? | ||
.into_iter() | ||
.map(crate::convert_subscription_result) | ||
.collect()) | ||
} | ||
} | ||
|
||
/// Unsubscribes from multiple topics. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it still experimental?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We haven't thought about it, but we've changed the API a couple of times already. So yeah, I'd consider it experimental still.