{"action":"closed","issue":{"url":"https://api.github.com/repos/caolan/async/issues/683","labels_url":"https://api.github.com/repos/caolan/async/issues/683/labels{/name}","comments_url":"https://api.github.com/repos/caolan/async/issues/683/comments","events_url":"https://api.github.com/repos/caolan/async/issues/683/events","html_url":"https://github.com/caolan/async/issues/683","id":52185789,"number":683,"title":"async.eachLimit final callback called multiple times","user":{"login":"moscoquera","id":1452208,"avatar_url":"https://avatars.githubusercontent.com/u/1452208?v=3","gravatar_id":"","url":"https://api.github.com/users/moscoquera","html_url":"https://github.com/moscoquera","followers_url":"https://api.github.com/users/moscoquera/followers","following_url":"https://api.github.com/users/moscoquera/following{/other_user}","gists_url":"https://api.github.com/users/moscoquera/gists{/gist_id}","starred_url":"https://api.github.com/users/moscoquera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/moscoquera/subscriptions","organizations_url":"https://api.github.com/users/moscoquera/orgs","repos_url":"https://api.github.com/users/moscoquera/repos","events_url":"https://api.github.com/users/moscoquera/events{/privacy}","received_events_url":"https://api.github.com/users/moscoquera/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/caolan/async/labels/question","name":"question","color":"ffffff"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2014-12-17T00:17:58Z","updated_at":"2015-05-19T19:14:51Z","closed_at":"2015-05-19T19:14:51Z","body":"i'm trying to use async.eachLimit to download multiple files at the same time using a ftp connection. my problem is that the ultimate function is called multiple times.\r\n\r\n     //entry point\r\n    me.client.list(remotePath+'/img',function(err,imagenes){\r\n\t\t\tif (err){\r\n\t\t\t\tconsole.log(err);\r\n\t\t\t\tthrow err;\r\n\t\t\t}\r\n\t\t\tfor(var index in imagenes){\r\n\t\t\t\tif (imagenes[index].type==='-'){\r\n\t\t\t\t\tvar tmpname = imagenes[index].name.replace(' ','_');\r\n\t\t\t\tme.ColaDescargas.push({\r\n\t\t\t\t\tremote:remotePath+'/img/'+tmpname,\r\n\t\t\t\t\tlocal:localpath+'/img/'+tmpname\r\n\t\t\t\t});\r\n\t\t\t}}\r\n\t\t\t//despues de tener las imagenes procesa la cola\r\n\t\t\tasync.eachLimit(me.ColaDescargas,ftpLimit,me.ProcesarColaDescargas.bind(me),function(err){\r\n\t\t\t\tif (err){\r\n\t\t\t\t\tconsole.log(err);\r\n\t\t\t\t}\r\n\t\t\t\tconsole.log(\"called just once\");\r\n\t\t\t});\r\n\t\t\t//me.ProcesarColaDescargas(localpath);\r\n\t\t});\r\n\r\n     ProcesarColaDescargas=function(sig,_callback){\r\n\t\tconsole.log('Descargando....')\r\n\t\tthis.client.get(sig.remote,function(err,stream){\r\n\t\t\tif (err){\r\n\t\t\t\tconsole.log('error descargando: '+sig.remote);\r\n\t\t\t\tif (sig.remote.toLowerCase().lastIndexOf('.json')===sig.remote.length-5){\r\n\t\t\t\t\t//_callback(err);\r\n\t\t\t\t\t}else{\r\n\t\t\t\t\t\t_callback();\r\n\t\t\t\t\t}\r\n\t\t\t\tconsole.log(err);\r\n\t\t\t\treturn;\r\n\t\t\t}else{\r\n\t\t\t\r\n\t\t\tstream.once('close',function(){\r\n\t\t\t\tconsole.log(\"close:\"+sig.remote);\r\n\t\t\t\t_callback(); //cuando acabe la descarga sigue con el siguente archivo\r\n\t\t\t});\r\n\t\t\ttry{\r\n\t\t\t\tvar ws = fs.createWriteStream(sig.local);\r\n\t\t\t\tstream.pipe(ws);\r\n\t\t\t\t\r\n\t\t\t}catch (exc){\r\n\t\t\t\tconsole.log('no se pudo crear el archivo:'+sig.local);\r\n\t\t\t\t//call();\r\n\t\t\t}\r\n\t\t\t}\r\n\t\t});\r\n\t\r\n      }"}}