nodejs中关于ES6的promise嵌套写法
我打算实现如下功能:插入主记录,返回insertId,然后插入明细记录
testObject.insertMain(code,name)
.then((result)=>{
var insertId = result.insertId;
testObject.insertDetail(insertId,........)
.then((result1)=>{
testObject.func3(......)
.then(..)
.catch(..)
})
.catch(..)
.catch(..)
这种逻辑似乎又进入了无限嵌套逻辑。求教如何写正确!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
把非 Promise 实现改造成 Promise 实现是个巨大的工程。如果都是 Promise 实现就好办了,第一个 Promise 的
then返回就是第2个 Promise 或者第二个then的值,就可以一直then下去了,最后来 catch 就行。xxx.then().then().then().then().catch()