I have these two functions: one which analyses some data, and the other feeds it some data. Here the one which analyses the data translates the given text and runs it through an NLU model on IBM's Watson. For now I just want to store all the analysis results into 1 single Array and log it in the console.
My code:
const analyzeTweet = function(tweet){
return new Promise((resolve,rejects)=>{
translator(tweet).then(translation => {
const options = {
text: translation.text,
features: {
entities: {model:auth.model},
relations:{model: auth.model}
},
};
nlu.analyze(options).then(responce => {
resolve(responce.result);
});
});
});
}
aggregate();
function aggregate(){
var analysis = []
incoming.forEach(tweet => {
result = analyzeTweet(tweet).then(result => {
analysis.push(result);
})
});
console.log(analysis);
}
the incoming
is irrelevent here
The problem is that when I run the script, I get this output:
[]
What could be wrong or what am I doing wrong. Any concepts do I need to learn in-depth about?