or Meteor.apply doesnt return anything

–Solved but kinda messy – Solution at 3rd comment–

I am trying to get users’ profile pictures, storing in user document like user.profile.pp.


getUserPpByUsername: function(username){
    return Meteor.users.findOne({username: username}).profile.pp;
    // It returns exactly what i want

The method returns value what i want, like: ‘http://pbs.twimg.imageimageimage

In my template helper i tried Meteor.apply:

getPpByAuthor: function(author){
    return Meteor.apply('getUserPpByUsername', [author], true, {returnStubValue: true});
    // undefined

Befor this i tried

getPpByAuthor: function(author) {
        return'getUserPpByUsername', author, function(error, result){
            return result;

Also i console.logged this return values, returned undefineds.

By the way, when i tried just

return Meteor.users.findOne({username: author}).profile.pp;

It returned just the currentUser’s pp value.

What i am missing?

Edit: I was using Session.set(‘returnThis’, result), and i was returning this with Session.get…
But now, i cant do this with Session.

Hope, i can explain my problem, sorry for bad english.

Tried with Future.

In server/init.js

Future = Npm.require('fibers/future');

getUserPpByUsername: function(username){
    var fut = new Future();
        fut.return(Meteor.users.findOne({username: username}).profile.pp);
    }, 50);
        return fut;

Returning undefined, still.

And i don’t get this How can i use it for my system, i tried some combinations but it didn’t worked, confused.

Solved with javascript trick.

In template.js

var imagesArray = [];
Template.template.helpers({'getUserPpByUsername', author, function(error, result){

        var boxes = document.querySelectorAll('paper-material');
        for(var i = 0;i < boxes.length;i++){
            boxes[i].querySelector('iron-image').setAttribute('src', imagesArray[i]);
    }, 1000);

Push all images into an array. Then setting src attribute etc. Thats all folks, i can sleep now like babies.

setting timeout is not a good way of doing this and will just cause trouble…use a reactive variable an set it once you get the data back from the method