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

undo some changes from #122 #123

Merged
merged 1 commit into from
Nov 1, 2023
Merged
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
43 changes: 23 additions & 20 deletions src/middlewares/subscriptions/merge_subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,31 +230,34 @@ impl Middleware<SubscriptionRequest, Result<(), StringError>> for MergeSubscript
.await?;

// broadcast new values
let mut stream = subscribe();

loop {
tokio::select! {
resp = stream.recv() => {
match resp {
Ok(new_value) => {
if let Err(e) = sink.send(new_value).await {
tracing::trace!("subscription sink closed {e:?}");
break;
tokio::spawn(async move {
// create receiver inside task to avoid msg been broadcast before stream.recv() is hit
let mut stream = subscribe();

loop {
tokio::select! {
resp = stream.recv() => {
match resp {
Ok(new_value) => {
if let Err(e) = sink.send(new_value).await {
tracing::trace!("subscription sink closed {e:?}");
break;
}
}
Err(e) => {
// this should never happen
tracing::error!("subscription stream error {e:?}");
unreachable!("subscription stream error {e:?}");
}
}
Err(e) => {
// this should never happen
tracing::error!("subscription stream error {e:?}");
unreachable!("subscription stream error {e:?}");
}
}
}
_ = sink.closed() => {
tracing::trace!("subscription sink closed");
break;
_ = sink.closed() => {
tracing::trace!("subscription sink closed");
break;
}
}
}
}
});

Ok(())
}
Expand Down