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

Is it possible to pause parsing and events emitting? #4

Closed
dobromyslov opened this issue Jan 29, 2021 · 3 comments
Closed

Is it possible to pause parsing and events emitting? #4

dobromyslov opened this issue Jan 29, 2021 · 3 comments

Comments

@dobromyslov
Copy link

Is your feature request related to a problem? Please describe.
Can't synchronously parse XML with nested async/await callbacks with sax-js (https://github.com/isaacs/sax-js).

Describe the solution you'd like
Looking for another sax lib which supports pause/resume parsing and events for synchronous XML processing with nested async/await callbacks.

Describe alternatives you've considered
Found one solution https://github.com/leoz/sax-parser but it does not support stream processing.

Additional context
Callback example:

console.log('Start');
await new Promise<void>(async (resolve) => {
  await new Promise<void>((resolve1) => {
    for (let i = 0; i < 1000000000; i++) {
    }
    console.log('First Level Promise End');
    resolve1();
  });
  console.log('Second Level Promise End');
  resolve();
});
@dobromyslov
Copy link
Author

Looks like https://github.com/sindresorhus/emittery with emitSerial along with input stream pause/resume could do the trick. Will give it a try.

@Maxim-Mazurok
Copy link
Owner

Привет :)
Thank you for your interest in this project!
This is (for the most part) is just a port of isaacs/sax-js library.
If what you're looking for is not present in isaacs/sax-js, then it's most likely not present in Maxim-Mazurok/sax-ts.

Regarding your question, it's kind of the point of this library that it's not synchronous.
You'll have to create your own wrapper to make it work as you want.
You can look at NPM for packages that depend on isaacs/sax-js, some of them will give you an idea of how to create such a wrapper.

@dobromyslov
Copy link
Author

Спасибо, Максим.

Found a cool lib saxes (https://github.com/lddubeau/saxes) written in TypeScript.
Also found an async/await solution from the exceljs developer described here lddubeau/saxes#32 (comment)

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

2 participants