0

I am quite new to NodeJs and need some help regarding flow.

So, I need to change some lib as it does not work for me. I have asny call and then right a way i have sync code. The thing is that sync code starts executing before asny part return data.

asny:

 xmlenc.encrypt(message, options509, function(err, result) {
        console.log("error:", err)
        message = result
        return message;

      })

sync right after asyn:

xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
    "<" + envelopeKey + ":Envelope " +
    xmlnsSoap + " " +
    "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
    encoding +
    this.wsdl.xmlnsInEnvelope + '>' +
    ((self.soapHeaders || self.security) ?
      (
        "<" + envelopeKey + ":Header>" +
        (self.soapHeaders ? self.soapHeaders.join("\n") : "") +
        (self.security && !self.security.postProcess ? self.security.toXML() : "") +
        "</" + envelopeKey + ":Header>"
      )
      :
        ''
      ) +
    "<" + envelopeKey + ":Body" +
    (self.bodyAttributes ? self.bodyAttributes.join(' ') : '') +
    (self.security && self.security.postProcess ? ' Id="_0"' : '') +
    ">" +
    genXML() +
    "</" + envelopeKey + ":Body>" +
    "</" + envelopeKey + ":Envelope>";

How to solve this that the progrem with wait for asyn part to return before moving to sync part.

thank you

user2017319
  • 77
  • 3
  • 6
  • What's with the "asny" word? You used it 4 times. -.- Anyway the whole point of async programming is that you run the code in the callback. Remove the `return` line and put your sync code there (I advice wrapping it with a separate function). – freakish Mar 12 '19 at 12:43
  • thank you. I can not use somehow of blocking part to black waiting func? – user2017319 Mar 12 '19 at 13:02
  • Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Patrick Hund Mar 12 '19 at 14:41

0 Answers0