Skip to content

Conversation

mbracher
Copy link

@mbracher mbracher commented Feb 19, 2023

In case of an endless stream, I noticed that the listener on the page is removed after pausing a subscription but on the rust side the stream keeps going. The effect is you will only data from one subscription but on the rust side it will keep publishing events for the old subscriptions.

Example of endless stream:

#[Subscription]
impl Subscription {
  async fn hello_world(&self) -> impl Stream<Item = String> {
    info!("rs2js hello_world subscribe");

      let mut value = 0;
      tokio_stream::wrappers::IntervalStream::new(tokio::time::interval(Duration::from_secs(1)))
          .map(move |_| {
              info!(?value, "rs2js hello_world produce");
              value += 1;
              format!("nr: {}", value)
          })

  }
}

I think in the case of a websocket transport the stream is ended because the client will send a 'teardown' message on unsubscribe or in case of page reload the websocket connection is closed which somehow also ends the stream at the rust side.

This pull request solves the case where client unsubscribes (urql pause). see #124
Not solved is the case where you can reload the page in a tauri app. Client will just start a new subscription and stream of old subscription alse keeps sending items.

Client was implemented with Sveltekit and @urql/svelte

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