Home > front end >  Best way to handle api callbacks in wordpos library?
Best way to handle api callbacks in wordpos library?

Time:02-10

I'm new handling promises in javascript and I've found a problem with this node js lib https://www.npmjs.com/package/wordpos I'm trying to find all the verbs that are found inside an arrays of strings, and for this I've created this function:

function calculateVerbsAmount(stringsArray) {
return stringsArray.map(function(item) { 
    let element = wordpos.getVerbs(item, function(result){
        return result;
    });    
});

}

What I expect is to have a new array, this time of verb strings, but since the lib handles the methods as callbacks I'm getting

[Promise { <pending> }, Promise { <pending> },
Promise { <pending> }, Promise { <pending> },
Promise { <pending> }, Promise { <pending> }]

I've tried added async/await but they always return the same result, any idea on how to do some synchronous call to the wordpos.getVerbs method?

CodePudding user response:

  •  Tags:  
  • Related