Promise has conditional judgment in then and returns different Promise objects. How can you determine which condition it comes from in the next then?

let p1 = ()=>{
    data = xxxx  // xxx   true  false
    return new Promise((res,rej)=>{
        res(data)
    })
}

// p2 p3 promise
let p2 = ....

let p3 = ....

// 
p1()
.then(
    (data)=>{
        if (data) {
            return p2
        } else {
            return p3
        }
    }
)
.then(
    //  p2 resolve p3  resolve
)
Mar.03,2021

to determine whether the resolve, of p2 or the resolve, of p3 is, in the final analysis, to determine whether the value of data is true or false, due to the limitation of passing the value of Promise chain calls, you can't get the data value inside the second then function of p1 (). There are two simple ways to judge:

  1. modify the p2Query p3 function with an extra data parameter. In the second then function, you can judge
  2. according to data.
  3. initialize a variable in the external environment in p1 ()
  

can't you mark p2 , p3 neutral flag ?

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2bf3e-2bae0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2bf3e-2bae0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?