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(..)
这种逻辑似乎又进入了无限嵌套逻辑。求教如何写正确!
Transforming non-Promise implementation into Promise implementation is a huge project. It would be easier if they were all implemented by Promise. The first Promise's
then
returns the value of the second Promise or the secondthen
, and you can keepthen
going on, and finally catch it.xxx.then().then().then().then().catch()