OneDrive 和 GDrive 中有 50 个文件夹,每个文件夹包含 500 个文件。
onedriveUrls
和gdriveUrls
是length
50 的数组,分别包含指向这些文件夹的链接。
混淆!以下代码预计会在2个级别并行运行,首先是async.parallel
,第二个是async.map
,是正确的代码还是async.map
应该包含在setTimeout
中以确保所有级别都并行运行?
async.parallel({
onedrive: function(callback){
async.map(onedriveUrls, request, function(err, results) {
if (err) throw(err); // handle error
callback(null,results);
});
},
gdrive: function(callback){
async.map(gdriveUrls, request, function(err, results) {
if (err) throw(err); // handle error
callback(null,results);
});
}
},
function(err, results) {
// results is now equals to: {onedrive: [array_of_length_x], gdrive: [array_of_length_y]}
});
async.map还返回了什么 - 承诺还是什么?
快乐帮助!
答案 0 :(得分:4)
是正确的代码还是async.map应该包含在setTimeout中以确保所有级别都是并行运行的?
没有。 SELECT
BANINST1_SZVIRST.SZVIRST_TERM_DESC,
SUM(IIF(BANINST1_SZVIRST.SZVIRST_FULL_PART_IND="F", 1, 0)) as [FullTime],
SUM(IIF(BANINST1_SZVIRST.SZVIRST_FULL_PART_IND="P", 1, 0)) as [PartTime],
SUM(IIF(SZVIRST_LEVL_CODE="01", 1, 0)) as [Graduate],
SUM(IIF(SZVIRST_LEVL_CODE="02", 1, 0)) as [UnderGraduate],
SUM(IIF(BANINST1_SZVIRST.SZVIRST_FULL_PART_IND="F" AND SZVIRST_LEVL_CODE="02", 1, 0)) AS [FullTimeUnderGraduates],
SUM(IIF(BANINST1_SZVIRST.SZVIRST_FULL_PART_IND="P" AND SZVIRST_LEVL_CODE="02", 1, 0)) AS [PartTimeUnderGraduates],
SUM(IIF(BANINST1_SZVIRST.SZVIRST_FULL_PART_IND="F" AND SZVIRST_LEVL_CODE="01", 1, 0)) AS [FullTimeGraduates],
SUM(IIF(BANINST1_SZVIRST.SZVIRST_FULL_PART_IND="P" AND SZVIRST_LEVL_CODE="01", 1, 0)) AS [PartTimeGraduates]
FROM BANINST1_SZVIRST
GROUP BY
BANINST1_SZVIRST.SZVIRST_TERM_DESC,
BANINST1_SZVIRST.SZVIRST_TERM_CODE,
BANINST1_SZVIRST.SZVIRST_LEVL_CODE,
BANINST1_SZVIRST.SZVIRST_FULL_PART_IND
WHERE BANINST1_SZVIRST.SZVIRST_TERM_CODE IN ("201020","201120","201220","201320","201420","201520","201620")
预计是异步的,一切都很好。在request
中包装任何内容都无济于事。
async.map还返回了什么 - 承诺还是什么?
无。 map
像大多数其他异步函数一样返回setTimeout
,它只用结果数组调用它的回调。
顺便说一句,您应该将代码简化为
undefined