Here are the codes to promise that i have written
module.exports['getTemplate'] = (object)=>{
return new Promise((fullfill,reject)=>{
var content = cache.get(object['template']);
if(content == null){
reader("./templates/"+object['template'],'utf8',function(err,data){
if(err){
reject(err);
} else{
cache.put(object['template'],data);
fullfill(data,object['data']);
1) ~~~~> console.log(object['data']);
}
});
}else{
fullfill(content,object['data']);
}
});
}
module.exports['render'] = (template,context)=>{
return new Promise((fullfill,reject)=>{
2 ~~~~~~> console.log(context);
try{
var html = mustache.render(template,context);
fullfill(html,context);
}catch(err){
reject(err);
}
});
}
and i am calling them using promise
in main app like
helper['parseJson'](item)
.then(helper['getTemplate'])
.then(helper['render'])
The problem is that the value is set in first console.log
but becomes undefined
in second function although the value of template is coming all fine. Can someone please explain to me where am i going wrong ?