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(api): writer & reader API #6

Closed
wants to merge 2 commits into from
Closed

feat(api): writer & reader API #6

wants to merge 2 commits into from

Conversation

iGxnon
Copy link
Member

@iGxnon iGxnon commented Jul 28, 2024

This PR changed the default API to use a more granular Writer API instead of the original Sink.

Signed-off-by: iGxnon igxnon@gmail.com

Signed-off-by: iGxnon <igxnon@gmail.com>
Signed-off-by: iGxnon <igxnon@gmail.com>
Copy link

codecov bot commented Jul 28, 2024

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

benches/bulk.rs Outdated
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bulk benchmark should be added back 😿

README.md Outdated
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrite readme

@@ -194,13 +194,11 @@ where
}
}

impl<F> Sink<Frame> for OutgoingGuard<F>
impl<F> Writer<Frame> for OutgoingGuard<F>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement default methods in Writer for it.

Comment on lines +38 to +78
// Send data to the destination
async fn send(dst: Pin<&mut impl Writer<Message>>, data: impl Iterator<Item = u8>) {
send_with_full(dst, data, Reliability::ReliableOrdered, 0).await;
}

async fn send_with_reliability(
dst: Pin<&mut impl Writer<Message>>,
data: impl Iterator<Item = u8>,
reliability: Reliability,
) {
send_with_full(dst, data, reliability, 0).await;
}

async fn send_with_order(
dst: Pin<&mut impl Writer<Message>>,
data: impl Iterator<Item = u8>,
order: u8,
) {
send_with_full(dst, data, Reliability::ReliableOrdered, order).await;
}

async fn send_with_full(
mut dst: Pin<&mut impl Writer<Message>>,
data: impl Iterator<Item = u8>,
reliability: Reliability,
order: u8,
) {
poll_fn(|cx| dst.as_mut().poll_ready(cx)).await.unwrap();
dst.as_mut()
.feed(Message::new(reliability, order, Bytes::from_iter(data)));
poll_fn(|cx| dst.as_mut().poll_flush(cx)).await.unwrap();
}

async fn flush(mut dst: Pin<&mut impl Writer<Message>>) {
poll_fn(|cx| dst.as_mut().poll_flush(cx)).await.unwrap();
}

async fn close(mut dst: Pin<&mut impl Writer<Message>>) {
poll_fn(|cx| dst.as_mut().poll_close(cx)).await.unwrap();
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add WriterExt

Comment on lines +102 to 106
/// Ping extension for client, experimental
pub trait Ping {
fn ping(self: Pin<&mut Self>) -> impl Future<Output = Result<(), Error>> + Send;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provide Ping support for the client.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, using WriterWrapper.

@iGxnon
Copy link
Member Author

iGxnon commented Aug 1, 2024

Closed cz we have implemented the FlushStrategy

@iGxnon iGxnon closed this Aug 1, 2024
@iGxnon iGxnon deleted the feat/writer-reader branch August 1, 2024 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant