我需要召集一系列承诺:
main(): Promise<any> {
1) call get();
2) then `get()` is finished call getTwo()
3) When `getTwo()` is finished return promise to main() function
}
get(): Promise<any> {
//
}
getTwo(): Promise<any> {
//
}
我试图证明我需要做什么。
答案 0 :(得分:1)
这是承诺链的方式:
return this.get()
.then(data1 => {
return this.getTwo(data1);
}).then(data2 => {
return data2;
})
有关详细信息,请 do read
更短的版本可能是@ JoeClay的评论
this.get().then(this.getTwo)
答案 1 :(得分:1)
你似乎在寻找
main(): Promise<any> {
return get().then(getTwo);
}
请注意,它没有&#34;返回对main()函数的承诺&#34;当getTwo
完成时,但会解析then
创建并立即返回的承诺。