Skip to content

Cancellation

kevin-montrose edited this page Apr 10, 2021 · 4 revisions

Cancellation

Introduction

Cesil methods that return a ValueTask or ValueTask<T> commonly take a CancellationToken in order to support requesting the cancellation of an async task. For more details, refer to Cancellation in Managed Threads.

Remarks

Cesil makes no guarantees about how often a CancellationToken will be consulted to determine if cancellation has been requested. That said, an attempt is made to check in at "reasonable" points - such as after a row is read/written or after an asynchronously continuation resumes.

Underlying async code that Cesil sits on top of (for example, a TextReader during async reading) will receive the CancellationToken that is provided (or CancellationToken.None if no token is provided). Cesil cannot make guarantees about how, and how often, such code uses the provided CancellationToken.

If cancellation is requested, the Cesil interface (a IReader<TRow>, IAsyncReader<TRow>, IWriter<TRow>, or IAsyncWriter<TRow>) will be "poisoned" as if any other exception was raised, and cannot be used post-cancellation. Additionally, Cesil makes no guarantees that any read or write operations in flight won't leave the underlying stream in an odd state - with a value partially written, or data read but not processed for example.

Clone this wiki locally