admin管理员组文章数量:1429327
I have this bit of code:
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);
});
I am getting this error:
TypeError: (intermediate value)(intermediate value).then is not a function at Array.fill.map.v (/home/oleg/WebstormProjects/oresoftware/live-mutex/.r2g/tests/smoke-test.js:26:6) at Array.map () at /home/oleg/WebstormProjects/oresoftware/live-mutex/.r2g/tests/smoke-test.js:20:43
It should be occurring on 5th line of code in the code snippet above.
I have this bit of code:
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);
});
I am getting this error:
TypeError: (intermediate value)(intermediate value).then is not a function at Array.fill.map.v (/home/oleg/WebstormProjects/oresoftware/live-mutex/.r2g/tests/smoke-test.js:26:6) at Array.map () at /home/oleg/WebstormProjects/oresoftware/live-mutex/.r2g/tests/smoke-test.js:20:43
It should be occurring on 5th line of code in the code snippet above.
Share Improve this question asked Jul 15, 2018 at 22:34 user7898461user7898461 1-
Make sure that
c.lockp('foo')
returns a promise. – Kosh Commented Jul 15, 2018 at 22:38
1 Answer
Reset to default 2Your .then
is being called on the function with the v
parameter (which is enclosed in the parentheses right before the .then
). Put the .then
outside instead, so that it gets called on the promise chain rather than on the callback:
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));
本文标签: javascriptIntermediate valuethen is not a functionStack Overflow
版权声明:本文标题:javascript - Intermediate value - then is not a function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745539045a2662407.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论