编辑代码

//程序运行完成时一定要有输出语句,本工具才能正确展示运行结果。 
console.log("Hello JSRUN!   \n\n         - from NodeJS .");

// 如果then中返回了一个promise 会将promise的结果继续传给第二then中
//(如果结果是将状态改成成功就走下一个then的成功回调,状态改为失败就走下一个then的失败回调)
function read(content) {
    return new Promise( (resolve, reject) => {
            setTimeout( function() {
                if(content > 3){
                    resolve('成功');
                }else{
                    reject('小于3: ' + content)
                }
            }
            , 1000)
        })
}

read(1).then( data=>{
    console.log(data)
}, error=>{
    console.log(error)
    return read(2).then( data=>{
        console.log(data)
    }, error=>{
        console.log(error)
        return read(3).then( data=>{
            console.log(data)
            }, error=>{
            console.log(error)        
        } )
    } )
} )