salsify/jsonstreamingparser

Ability to stop parsing from listener

MAXakaWIZARD opened this issue · 8 comments

Is there any ability to stop parsing process from listener?

What do you mean stop ?
Le sam. 12 mars 2016 à 21:59, Max Grigorian notifications@github.com a
écrit :

Is there any ability to stop parsing process from listener?


Reply to this email directly or view it on GitHub
#38.

@soyuka I mean for example I have very large file and need to stop parsing earlier (process only few items from the start).

You have to implement a listener that allows you to stop after x items. You'll have to handle yourself how to start at the previous and etc.
IMO, you may not need to implement this as this library ables you to handle objects with a very low memory footprint.

I need this anyway, because file parsing takes 1 min to process all file and I need to break early. And I do not see how this can be done from listener. Maybe I'm missing something.

Would be a relatively easy change if you want to submit a pull request. You'd just need to add a method to the parser called stop() which would set a flag which would cause the parse() method to break out of the loop reading characters.

Happy to look at a PR if you want to submit it.

@gonzofy I'm looking forward to make a PR for this. In your proposed solution there must be access to parser instance from inside the listener. But I don't think this is a big deal.

Exactly. I don't think you can simply stop the parsing without modifying the parser itself since that loop essentially runs the application thread until it's finished parsing the file.

@gonzofy Please review #39