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

Replace stream::select to stream_select! #414

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use tokio::io::{AsyncRead, AsyncWrite};
use tokio_util::codec::{FramedRead, FramedWrite};

use futures::channel::mpsc;
use futures::{future, join, stream, FutureExt, Sink, SinkExt, Stream, StreamExt, TryFutureExt};
use futures::{
future, join, stream, stream_select, FutureExt, Sink, SinkExt, Stream, StreamExt, TryFutureExt,
};
use tower::Service;
use tracing::error;

Expand All @@ -27,7 +29,7 @@ const MESSAGE_QUEUE_SIZE: usize = 100;
/// This socket handles the server-to-client half of the bidirectional communication stream.
pub trait Loopback {
/// Yields a stream of pending server-to-client requests.
type RequestStream: Stream<Item = Request>;
type RequestStream: Stream<Item = Request> + Unpin;
Copy link
Author

Choose a reason for hiding this comment

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

Note: Breaking change, but it still pass the unit tests + works with stdio. Required by stream_select!

/// Routes client-to-server responses back to the server.
type ResponseSink: Sink<Response> + Unpin;

Expand Down Expand Up @@ -119,8 +121,8 @@ where
.map(|res| Ok(Message::Response(res)))
.forward(responses_tx.clone().sink_map_err(|_| unreachable!()))
.map(|_| ());

let print_output = stream::select(responses_rx, client_requests.map(Message::Request))
let print_output = stream_select!(responses_rx, client_requests.map(Message::Request))
.map(Ok)
.forward(framed_stdout.sink_map_err(|e| error!("failed to encode message: {}", e)))
.map(|_| ());
Expand Down