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

Unsubscribe is not implemented #124

Open
mbracher opened this issue Feb 19, 2023 · 0 comments
Open

Unsubscribe is not implemented #124

mbracher opened this issue Feb 19, 2023 · 0 comments

Comments

@mbracher
Copy link

When creating an endless stream it does not get closed when (svelte) Client is unsubscribing (urql pause) or when the page is reloaded.
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)
          })

  }
}
<script lang="ts" >
  import { debugExchange, createClient, setContextClient, queryStore, gql, subscriptionExchange, subscriptionStore} from '@urql/svelte';
  import { invokeExchange, subscribe } from "tauri-plugin-graphql-urql";

  const gql_client = createClient({
    url: 'graphql',
    exchanges: [
      invokeExchange, 
      subscriptionExchange({
        forwardSubscription: (operation) => ({
          subscribe: (sink) => ({
            unsubscribe: subscribe(operation, sink),
          }),
        }),
      }),
    ]
  });

  const messages = subscriptionStore({
    client: gql_client,
    query: gql`
      subscription MessageSub {
        helloWorld 
      }`
  });

  function startSubscription() {
    messages.resume();
  }
  function stopSubscription() {
    messages.pause();
  }
</script>

{#if !$messages}
  <p>No new messages</p>
{:else}
  {JSON.stringify($messages.data)}
{/if}
<button on:click="{stopSubscription}">stop</button>
<button on:click="{startSubscription}">start</button>
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

No branches or pull requests

1 participant