I am currently working on developing a Dapp that is connected with the Ethereum Blockchain. Within this project, I have created a JavaScript function that invokes asynchronous methods.
async function getFiles(id, array){
if(id < 2){
myContract.consultFile.call(id,"0x2b461Db580028F263351B969cFd8542db696787E",function(err, res){
array.push({title : res[0], description : res[1]});
getFiles(++id, array);
});
}
return array;
}
Do you think this initial function should be asynchronous?
In addition, I have a helper function that calls the aforementioned one. I have made some attempts but it is returning a promise object.
After using console.log()
, I can see that the [[PromiseValue]] is correct.
However, when trying to display it in my view using {{#each files}} with the code below, nothing seems to happen. If I return tmp, I see [Object Promise].
Is the array being successfully sent? How can I properly display the array?
Template.myDocuments.helpers({
'files': function(){
var tmp = getFiles(0,[]);
tmp.then(function(val){
console.log(val);
return val;
});
}
});