Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Would you please provide a sync version of parseString #379

Closed
zszszsz opened this issue Apr 28, 2017 · 9 comments
Closed

Would you please provide a sync version of parseString #379

zszszsz opened this issue Apr 28, 2017 · 9 comments

Comments

@zszszsz
Copy link

zszszsz commented Apr 28, 2017

It is strange to provide only async functions without providing sync versions of them. :-)

@zszszsz
Copy link
Author

zszszsz commented Apr 28, 2017

While what I find I am wrong is that the "async" version is not async at all.

Strange behavior, indeed.

I am going to close this issue,
but try this please,
and you will find the behavior of this function is strange:

(() => {
    var a;
    new require('xml2js').Parser().parseString('<xml>asdf</xml>', (e, r) => { a = r });
    console.log(a);
})();

@zszszsz zszszsz closed this as completed Apr 28, 2017
@Leonidas-from-XIV
Copy link
Owner

Leonidas-from-XIV commented Apr 28, 2017 via email

@ghostcode
Copy link

very confused!

@Leonidas-from-XIV
Copy link
Owner

Leonidas-from-XIV commented May 6, 2017 via email

@sirius1024
Copy link

@Leonidas-from-XIV I think it's confused because I have to told everyone of my colleagues that the function is SYNC actually……anyway, It won't be a big problem~
Thanks for your help.

@sirius1024
Copy link

sirius1024 commented Jan 12, 2018

@zszszsz so the right way to use this lib is:

let parsed;
parseString(msgBody.message, (err, rst) => {
     parsed = rst;
});
console.log(`${parsed}`);

BTW It did take me some time because in my mind I think everything is OK with await when I saw the callback function.

@Leonidas-from-XIV
Copy link
Owner

Leonidas-from-XIV commented Jan 12, 2018 via email

@sirius1024
Copy link

@Leonidas-from-XIV
all right, let's back to confused. 😂

@zszszsz
Copy link
Author

zszszsz commented Jan 12, 2018

@sirius1024 or maybe you are also interested in #380.

Anyway this issue is a closed one with proper solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants