CsvHelper icon indicating copy to clipboard operation
CsvHelper copied to clipboard

Add cancellation to async methods

Open Weldryn opened this issue 5 years ago • 2 comments

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.

Weldryn avatar Jul 19 '19 13:07 Weldryn

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?

JoshClose avatar Oct 09 '22 20:10 JoshClose

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.

chasse20 avatar Jul 08 '23 00:07 chasse20