isaacs / sax-js

A sax style parser for JS
Other
1.09k stars 325 forks source link

Are Promises supported (asynchronous callbacks)? #248

Open pkrukp opened 4 years ago

pkrukp commented 4 years ago

Hi,

I'm trying to figure out if I can do sax.createStream().on("opentag", async (node) => { ... - will sax wait for Promise returned by the callback?

I searched code on github for "Promise", "then", "catch" but found nothing, so I suppose it won't?

dobromyslov commented 3 years ago

Yes. But if your async callback has nested promises and awaits for them then you will struggle Events-vs-Promises execution order because sax-js will not pause generation of new events. And there is no pause method to stop events. Even readable stream pause method will not help to achieve synchronous processing.

dobromyslov commented 3 years ago

@pkruk2 have a look at this solution: https://github.com/lddubeau/saxes/issues/32#issuecomment-640493042