CsvHelper
CsvHelper copied to clipboard
Add cancellation to async methods
Is your feature request related to a problem? Please describe. I/O bound async operations (ReadAsync/WriteAsync) should be cancelable in case the operation need to be stopped for whatever reason (external event, timeout, optimistic branching, etc). I think anyone want to keep control on the process they create.
Describe the solution you'd like
- Add a
CancellationToken
parameter for every async operation - Make use of the cancellation token inside the async operation for it to be "cancellation aware"
- Pass the cancellation token to sub async methods
Describe alternatives you've considered There is no clean alternatives except side monitoring the async operation and react (close the stream then retry?) to the cancellation in the scope around the async operation that does not support the cancellation operation. It is time/resource consuming and bad practice.
There is no place where an async read or write happens that a cancellation token can be passed in. Should this still be implemented? If yes, then shouldn't it be added to the GetRecords
and WriteRecords
methods also since they're long running?
Thank you for writing an awesome library Josh! I could be wrong, but one method that still may benefit from a token argument is the FlushAsync chain.
Also when you going to add a donation/sponsor link in Github or at least a BTC wallet? You literally have one of the best CSV tools for .NET, and I was about to drop a hundo tip.