0

I have an issue where function callWebsocket is not getting paused for def.preProcessor dialog box action. As a result this.ws.call is getting evaluated. I want this.ws.call to wait for the results of def.preProcessor dialog box action.

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) => {
});
}
}
vector8188
  • 1,293
  • 4
  • 22
  • 48
  • does putting last 2 lines inside if statement help? surely you only want to execute them after await completes. – danday74 Oct 09 '18 at 17:31
  • `preProcessor` states it is `async`, but does nothing asynchronously; therefore it will run synchronously. Return a Promise that resolves when the `confirm` subscription is resolved. – Heretic Monkey Oct 09 '18 at 17:32
  • You need to make a promise from your `self.dialog.confirm(…).subscribe(…)` callback that you can return from `preProcessor` to await it. – Bergi Oct 09 '18 at 17:45

0 Answers0