title: Svelte: How to manually stop subscribe?
body: <p>I have a store that fetches data once in a while – according to user's actions. This is a store because its data is used globally and mainly all components needs the latest data available.</p>
  <p>But, for one specific component, I only need the first data loaded.</p>
  <p>For this component, there is no reason to keep a <code>subscribe()</code> function running after the first fetch. <strong>So, how can I stop this subscribe function?</strong></p>
  <p>The only example in <a href="https://svelte.dev/tutorial/auto-subscriptions" rel="nofollow noreferrer">Svelte doc's</a> uses <code>onDestroy()</code>, but I need to manually stop this <code>subscribe()</code>.</p>
  <p>I tried with a simple &quot;count&quot; (if count &gt; 1, unsubscribe), but it doesn't work.</p>
  <pre class="lang-js prettyprint-override"><code>    import user from './store'
      
      let usersLoaded = 0
      
      const unsubscribe = user.subscribe(async (data) =&gt; {
          if(data.first_name !== null) {
              usersLoaded = usersLoaded + 1
          }
          
          if(usersLoaded &gt; 1) {
              unsubscribe;
          }
      });
  </code></pre>
  <p>Here's a full working REPL:</p>
  <p>→ <a href="https://svelte.dev/repl/95277204f8714b4b8d7f72b51da45e67?version=3.35.0" rel="nofollow noreferrer">https://svelte.dev/repl/95277204f8714b4b8d7f72b51da45e67?version=3.35.0</a></p>