var Crawler = require("simplecrawler");
var cheerio = require('cheerio');
var linkResultsA = [];
var crawlResults = 0;

var crawlResultPage = function(count, url, year)  {
  //console.log(count + ": " + url);
  var resultpagecralwer = Crawler(url)
    .on("fetchcomplete", function(queueItem, responseBuffer, response) {
      //console.log(count + ": It was a resource of type %s", response.headers['content-type'] + ". Url: " + url);

      var $ = cheerio.load(responseBuffer.toString());
      var rows = $("tr[bgcolor='#000066']").parent();
      var breakForPlatzierung = false;
      $(rows).each(function() {
        $(this).find('tr').each(function(i, el) {
          $(this).find('td').each(function(i, el) {
            //console.log("Break is: " + breakForPlatzierung);
            if (breakForPlatzierung) {
              $(this).find('a').each(function(i, el) {
                if ($(this).attr('href').indexOf("saisonpl%3D" + year) > -1) {
                  //console.log("Pushed to linkResultsA");
                  linkResultsA.push({
                    "count": count,
                    "href": $(this).attr('href'),
                    "year": year
                  });
                }
              });
            }
            if ($(this).text().indexOf("Platzierungen in ") > -1) {
              breakForPlatzierung = true;
            }
          });
        });
      });
      crawlResults++;
    })
    .on("complete", function() {
      if (count % 50 == 0) console.log(count + " page results from cyclists in " + year + " already crawled");
    })
    .on("fetchclienterror", function(queueItem, error) {
      console.error("Error: " + error);
    })
    .on("fetchtimeout", function(queueItem, crawlerTimeoutValue) {
      console.error("Timedout after " + crawlerTimeoutValue);
    })
    .on("queueerror", function(error, URLData) {
      console.error("Could not add to queue: " + error);
    })
    .on("fetchconditionerror", function(queueItem, error) {
      console.error("Error: " + error);
    })
    .on("cookieerror", function(queueItem, error, cookie) {
      console.error("Error: " + error);
    })
    .on("downloadconditionerror", function(queueItem, error) {
      console.error("Error: " + error);
    })
    .on("fetcherror", function(queueItem, response) {
      console.error("Error: " + response);
    })
    .on("gziperror", function(queueItem, responseBody, response) {
      console.error("Error: " + response);
    })
    .on("fetchdataerror", function(queueItem, response) {
      console.error("Error: " + response);
    })
    .on("robotstxterror", function(error) {
      console.error("Error: " + error);
    });


  resultpagecralwer.decodeResponses = true;
  resultpagecralwer.maxDepth = 1;
  resultpagecralwer.start();
};

var checkFinish = function(resolve, amount) {
  console.log(crawlResults + " / " + amount);
  if (crawlResults == amount) {
    resolve(linkResultsA);
  } else  {
    setTimeout(function() {
      checkFinish(resolve, amount);
    }, 500);
  }
}

var doTimeout = function(count, href, year)  {
  setTimeout(function() {
    crawlResultPage(count, href, year);
  }, count * 1000);
}

async function start(cyclisters, year) {
  return new Promise(async (resolve, reject) => {
    for (var i = 0; i < cyclisters.length; i++) {
      //console.log("Crawling " + cyclisters[i].href);
      doTimeout(i, cyclisters[i].href, year);
    }
    checkFinish(resolve, cyclisters.length - 1);
  });
}
module.exports = {
  start: start
};

@@ -148,18 +148,12 @@
 ion(
-count, 
 url
+s
 , ye
@@ -233,16 +233,25 @@
 wler(url
+s%5B0%5D.href
 )%0A    .o
@@ -1429,59 +1429,26 @@
     
-%7D)%0A    .on(%22complete%22, function() %7B%0A      if (count
+  if (crawlResults
  %25 5
@@ -1464,28 +1464,35 @@
 onsole.log(c
-ount
+rawlResults
  + %22 page re
@@ -1545,32 +1545,113 @@
 awled%22);%0A    %7D)%0A
+    .on(%22complete%22, function()%7B%0A      console.log(%22Sollte fertsch sein%22);%0A    %7D)%0A
     .on(%22fetchcl
@@ -2812,16 +2812,108 @@
 th = 1;%0A
+  for (var i = 1; i %3C urls.length; i++) %7B%0A    resultpagecralwer.queueURL(urls%5Bi%5D.href);%0A  %7D%0A
   result
@@ -3171,17 +3171,18 @@
 %0A    %7D, 
-5
+20
 00);%0A  %7D
@@ -3189,359 +3189,119 @@
 %0A%7D%0A%0A
-var doTimeout = function(count, href, year)%C2%A0 %7B%0A  setTimeout(function() %7B%0A    crawlResultPage(count, href, year);%0A  %7D, count * 1000);%0A%7D%0A%0Aasync function start(cyclisters, year) %7B%0A  return new Promise(async (resolve, reject) =%3E %7B%0A    for (var i = 0; i %3C cyclisters.length; i++) %7B%0A      //console.log(%22Crawling %22 + cyclisters%5Bi%5D.href);%0A      doTimeout(i, 
+async function start(cyclisters, year) %7B%0A  return new Promise(async (resolve, reject) =%3E %7B%0A    crawlResultPage(
 cycl
@@ -3306,24 +3306,16 @@
 clisters
-%5Bi%5D.href
 , year);
@@ -3315,22 +3315,16 @@
  year);%0A
-    %7D%0A
     chec

Use queuefunction