暂停功能以使用异步/等待执行

时间:2018-10-09 17:25:44

标签: javascript angular async-await

我遇到一个问题:callWebsocket对话框动作的功能def.preProcessor没有被暂停。结果this.ws.call得到评估。我希望this.ws.call等待def.preProcessor对话框操作的结果。

export class ApiService {
    VmStart:{
  apiCall:{
....
  },
  async preProcessor(def:ApiCall, self ) {
    self.dialog.confirm("OverCommit","Overcommit memory?").subscribe((res)=>{
      console.log(res);
    });
    return def;
  },
},

}



async callWebsocket(evt:CoreEvent,def){
let cloneDef = Object.assign({}, def);

if(evt.data){
  cloneDef.apiCall.args = evt.data;

  // PreProcessor: ApiDefinition manipulates call to be sent out.
  if(def.preProcessor){
    cloneDef.apiCall = await def.preProcessor(def.apiCall, this);
  }
  let call = cloneDef.apiCall;//this.parseEventWs(evt);
  this.ws.call(call.namespace, call.args).subscribe((res) => {
});
}
}

0 个答案:

没有答案