0
votes

This is another asynchronous topic for meteor, and i'm sorry for that ! I read so much things about wrapasync, promise, future, fibers etc... that i'm a bit lost !

My problem is simple, in my code I just want a return of the server who is returning the current hostname from :

"getHost" : function(){
      return this.connection.httpHeaders.host;
 }

I'm calling this at the beggining of my program in the onCreated helper :

Template.printjoblistList.onCreated(function () {
    Meteor.call("getHost", function(err, data){
        if(err){
            console.log("error " + err + " : " + data);
        }else {
            Session.set("printJobList_Host", data)
        }
    });
});

The problem is : I have my Session.set who are executed after my Session.get. This Session.get is executed by this :

In my template :

<a href="{{getPdf}}">{{getPdf}}</a>

In my helper :

Template.registerHelper("getPdf", function() {
    var myReturn = Session.get('printJobList_Host'); + "/pdf/" + pdfFileName;
    return myReturn;
});

So, I would like to understand how to use wrapAsync to get this clearly ! Thanks for your help !

1
On the client, you can't. wrapAsync is to make asynchronous code look synchronous thanks to Fibers and only work in a Node environment (the server). On the client, you're stuck with classical asynchronous. - Kyll

1 Answers

1
votes

The Session.get may happen before the Session.set, but that should be fine, because when the Session.set is called, the Session.get will be called again too (at least it is the case in a regular helper.)

If that doesn't work for you, try using the Session.get inside a Tracker.autorun()