定义异步函数
testOne(resolve:any, reject:any){
setTimeout(() => {
resolve("one");
}, 3000);
}
testTwo(resolve:any, reject:any){
setTimeout(() => {
resolve("two");
}, 3000);
}
testThree(resolve:any, reject:any){
setTimeout(() => {
resolve("three");
}, 3000);
}
定义 Promise
let result = new Promise(this.testOne)
.then((resultOne)=>{
console.log(resultOne);
return new Promise(this.testTwo);
})
.then((resultTwo)=>{
console.log(resultTwo);
return new Promise(this.testThree);
})
.then((resultThree)=>{
console.log(resultThree);
});
console.log(result);
网友评论