title: Using a Meteor Subscription handle's .ready() function as a reactive source when Subscription is in a Deps.autorun
body: <p>So I have a subscription in a Deps.autorun and I want to keep track of when the subscription is still loading documents and when it has finished or "ready."</p>
  
  <p>I want to use the .ready() function on the handle that is returned by the Meteor.Subscribe method as a reactive data source in a handlebars helper. This works fine for the first subscription. But when the Deps is invalidated and the subscription is re-run, the handlebars template is not re-run.</p>
  
  <p>I assume this is because the .ready() on the subscription handle is not getting in-validated. In other words the dependency created for the handlebars helper is on the old .ready() reactive element and when the Deps.autorun is re-run and the subscription re-set there is a new handle and the handlebars helper isn't dependent on this new .ready() function.</p>
  
  <p>My workaround is to create a session variable within the Deps.autorun set to false, then pass an onReady callback function to the subscription which sets that session variable to true.</p>
  
  <p>Here is my original code which only works for the first subscription.</p>
  
  <pre><code>var searchResultsHandle = null;
  
  Deps.autorun(function () {
      searchResultsHandle = Meteor.subscribe("searchResults", Session.get('searchQuery'));
  });
  
  Handlebars.registerHelper("searchResultsLoaded", function() {
      return searchResultsHandle &amp;&amp; searchResultsHandle.ready();
  });  
  </code></pre>
  
  <p>And my workaround:</p>
  
  <pre><code>var searchResultsHandle = null;
  
  Deps.autorun(function () {
      Session.set('searchResultsLoaded', false);
      searchResultsHandle = Meteor.subscribe("searchResults", Session.get('searchQuery'), function(){
          Session.set('searchResultsLoaded', true);
      });
  });
  
  Handlebars.registerHelper("searchResultsLoaded", function() {
      return Session.equals('searchResultsLoaded', true);
  });
  </code></pre>
  
  <p>Is that the right way to solve the issue? Is there any way to still use the .ready() function as a reactive datasource and re-subscribe in this way?</p>