bokuweb / docx-rs

:memo: A .docx file writer with Rust/WebAssembly.
https://bokuweb.github.io/docx-rs/
MIT License
334 stars 57 forks source link

Enable a means of curtailing read_docx? #653

Open Mrodent opened 11 months ago

Mrodent commented 11 months ago

Is your feature request related to a problem? Please describe.

Inability to end parsing mid-stream In a Rust context, if I am parsing multiple large .docx documents in parallel threads, it can take a significant time for read_dox() to end, and there could be a fairly simple way of tweaking your code to detect an AtomicBool

Describe the solution you'd like

Provide an AtomicBool called "stop_parse" or something. The user could then set that to true in an independent thread. The code used by read_dox() would be liberally sprinkled with a test to detect that "stop_parse" was now at true, and would exit the parsing ASAP. Graceful shutdown in other words.

Describe alternatives you've considered

It is possible to run in another process and kill the process. Or just wait for the long thread task(s) to end, accepting that a number of threads will be needlessly occupied for a second or more after the stop instruction is given.

Additional context

This is powerful code which on a big file leads to substantial processing. It would be nice to provide a means of shutting down gracefully. 🥰