我有这段代码:
const promises = new Array(20).fill(null).map(v => {
return c.lockp('foo').then((v => {
const rand = Math.random()*3000;
return new Promise((resolve) => setTimeout(resolve,rand)).then(_ => v);
})
.then(({key, id}) => c.unlockp(key, id)));
});
return Promise.all(promises)
.then(values => {
console.log('all good');
process.exit(0);
});
我收到此错误:
TypeError:(中间值)(中间值)。那么不是 功能 在Array.fill.map.v(/home/oleg/WebstormProjects/oresoftware/live-mutex/.r2g/tests/smoke-test.js:26:6) 在Array.map() 在/home/oleg/WebstormProjects/oresoftware/live-mutex/.r2g/tests/smoke-test.js:20:43
它应该出现在上面代码段的第五行代码中。
答案 0 :(得分:2)
正在使用x <- Macro[1:13,3:21]
x <- as.matrix(x)
y <- Macro[1:13,2:2]
y <- as.matrix(y)
myfit <- caret::train(x,y,
method = "glmnet",
tuneGrid = expand.grid(.alpha = seq(.05, 1, length = 15),
.lambda = c((5:10)/10)))
参数(该函数包含在.then
之前的括号中)调用v
。将.then
放在外部,以便在promise链而不是回调中调用它:
.then