私は一生、これに対する答えを見つけることができません。caolan の async.js ノード モジュールを使用して、async.each の iterator 関数にパラメーターを渡すにはどうすればよいですか? イテレータを再利用したいのですが、コンテキストに基づいて別のプレフィックスで保存する必要があります。私が持っているものは次のとおりです。
async.each(myArray, urlToS3, function(err){
if(err) {
console.log('async each failed for myArray');
} else {
nextFunction(err, function(){
console.log('successfully saved myArray');
res.send(200);
});
}
});
function urlToS3(url2fetch, cb){
//get the file and save it to s3
}
私ができるようにしたいのは:
async.each(myArray, urlToS3("image"), function(err){
if(err) {
console.log('async each failed for myArray');
} else {
nextFunction(err, function(){
console.log('successfully saved myArray');
res.send(200);
});
}
});
function urlToS3(url2fetch, fileType, cb){
if (fileType === "image") {
//get the file and save it to s3 with _image prefix
}
}
coffeescript について同様の質問を見つけましたが、答えはうまくいきませんでした。慣用的ではないことをしようとしている場合に備えて、リファクタリングを受け入れますが、これは非常に論理的なことのようです。