0

In the below code:`

    function extract_nouns_from_reviews (reviews,callback){

      reviews.forEach(function(review,index){

          wordpos.getNouns(review,function(result){

              result.forEach(function(noun,index){
                 noun_set.add(noun);
                 //callback(noun_set);
              });

          });

      });
      //callback(noun_set);
   }

How do I return the result - noun_set via the callback ? Or is there any better way to accomplish this task ?

Maroof
  • 139
  • 1
  • 12

1 Answers1

0

You can try async library to solve the problem.

var async = require('async');

function extract_nouns_from_reviews (reviews,callback){
   async.each(reviews, function(review, cb){
     wordpos.getNouns(review, function(result){
       result.forEach(function(noun){
         noun_set.add(noun);
       });
       cb();
     });
   }, function(err){
     callback(noun_set);
   });  
}
Mukesh Sharma
  • 8,914
  • 8
  • 38
  • 55