我有这个有效的代码:
require! [async]
action = for let m from 1 to 12
(p) ->
p null, m
err, data <- async.series action
console.log data
但我很难让代码在嵌套循环上工作:
action = for let m from 1 to 12
for let d from 1 to 12
(p) ->
p null, (m + "-" + d)
err, data <- async.series action
console.log data
错误信息:
fn(function (err) {
^
TypeError: object is not a function
根据评论的要求,编译后的 js 代码,由 Livescript 生成:
var async, action, res$, i$;
async = require('async');
res$ = [];
for (i$ = 1; i$ <= 12; ++i$) {
res$.push((fn$.call(this, i$)));
}
action = res$;
async.series(action, function(err, data){
return console.log(data);
});
function fn$(m){
var i$, results$ = [];
for (i$ = 1; i$ <= 12; ++i$) {
results$.push((fn$.call(this, i$)));
}
return results$;
function fn$(d){
return function(p){
return p(null, m + "-" + d);
};
}
}