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

fix: always send subscription id first #22

Merged
merged 1 commit into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/pub_sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ pub fn add_pub_sub<T: Send + 'static>(
tokio::pin!(stream);
loop {
tokio::select! {
biased;
msg = stream.next() => {
match msg {
Some(msg) => {
Expand Down
10 changes: 7 additions & 3 deletions src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ pub async fn serve_stream_sink<E, T: Metadata + From<Session>>(
let mut shutdown = config.shutdown_signal;
loop {
tokio::select! {
// Always poll the result stream first, so that subscription id will
// be sent before subscription messages (which might have already
// been sent to the rx channel by the publishing task).
biased;
result = result_stream.next() => {
match result {
Some(result) => {
Expand All @@ -164,12 +168,12 @@ pub async fn serve_stream_sink<E, T: Metadata + From<Session>>(
Some(msg) = rx.recv() => {
sink.send(StreamMsg::Str(msg)).await?;
}
_ = &mut dead_timer, if config.keep_alive => {
break;
}
_ = ping_interval.tick(), if config.keep_alive => {
sink.send(StreamMsg::Ping).await?;
}
_ = &mut dead_timer, if config.keep_alive => {
break;
}
_ = &mut shutdown => {
break;
}
Expand Down
Loading