How to show waiting when code process for along time (report generate)?

I want to show spinner waiting when I generate report for along time.
Example

// Template
{{#if data}}
   Show result
{{else}}
    No result
{{/if}}

// Helper
Template.myTemplate.helpers({
   data: function(){
      var data = ..............
       // get data from database and calculate
       // waiting
      
      if(data.count() > 0){
          return data;
      }else{
          return false; 
      }
   }
})
...
{{#if waiting}}
  {{> spinner}}
{{/if}}

Template.myTemplate.helpers({
  data: function () {
    //waiting
    Session.set("waiting", true);

   if (data.count() > 0) {
     // not waiting anymore
     Session.set("waiting", false);
  },
  waiting: function () {
    return Session.get("waiting");
  }
})

Thanks, I will try :smiley:

I tried, but don’t show spinner when waiting the result.
And then I custom like this

Template.myTemplate.onRendered(function(){
     //waiting
     Session.set("waiting", true);
});

Template.myTemplate.helpers({
  data: function () {

   if (data.count() > 0) {
     // not waiting anymore
     Session.set("waiting", false);
  },
  waiting: function () {
    return Session.get("waiting");
  }
})

It show spinner forever.

See here or Google “javascript sleep”.

Now I see why Session should not be in documentation :smiley:

And set that waiting variable true on same spot as u are instructing app to start generating report
If you really need to use Session, than use Session.setDefault in onRendered, to not overwrite it for no reason.

Are you setting the session before returning your data?

Yes I setting the session before.