dijs / wiki

Wikipedia Interface for Node.js
MIT License
315 stars 61 forks source link

wiki.page() giving socket hangup error for more length data #4

Closed riteshbabu closed 10 years ago

riteshbabu commented 10 years ago

userdata = ['Narendra Modi','Salman Khan','Narendra Prasad', 'Narendra Karmarkar','Narendra Hirwani','Bill Gates', 'Elon Musk', 'Michael Jackson', 'Bob Dylan'];

 for(var i = 0; i < userdata.length; i++) {
  console.log(userdata[i]);
  wiki.page(userdata[i], function(err, page) {
    console.log(page);
  });
 }

In this case i am getting error socket hangup.If array length is less than its working fine. Please can you give solutions for this.

dijs commented 10 years ago

The wiki.page method is asynchronous, and you are using it in a functional way. If you need to iterate over elements while processing them asynchronously, I would use a library like async https://github.com/caolan/async to help that functionality. I have also added a test that specifically tests your code above, I would have a look at that test.