在组件(或服务)中,我调用 Main 方法,该方法又调用另外 2 个私有方法。
export class MyService
{
private Stage1 (N : number)
{
console.log ('-->Stage1');
for (let i=0;i<N;i++)
{
//Send HTTP request
}
console.log ('<--Stage1');
}
private Stage2 (N: number)
{
console.log ('-->Stage2');
for (let i=0;i<N;i++)
{
//Send HTTP request
}
console.log ('<--Stage2');
}
public Main ()
{
this.Stage1 (5);
this.Stage2 (7);
}
}
问题:我希望仅在 Stage1 完成后才调用 Stage2。目标是获得以下输出:
-->Stage1
<--Stage1
-->Stage2
<--Stage2
您能否建议我应该在代码中添加什么内容?我尝试过:
async public Main ()
{
await this.Stage1 ();
await this.Stage2 ();
}
但这一概念失败了。
谢谢你,Zvika