Typically, under C# when you use Cancellation Token (with either async/await or normal threads) you either detect that the cancellation has been invoked and then exit whatever you are doing and return normally or throw a cancellation exception. In either cases, the function either returns/ends normally or unwinds. The API on the Cancellation Token allows for easily throwing the âCanceled Exceptionâ through the âThrowIfCanceledâ method. Or you can simply check if canceled.
For a thread, if the cancellation exception is thrown, then the parent thread can introspect the exception by joinging/asking for it. For a âCancellation Thrownâ task, what was waiting on the task can either throw the exception as well, or, introspect the exception.
I would think Rust would work similarly. Either return a Result(CancellationError) (or something like that) or simply Panic/Unwind (depending on use-case).
As long as the Futures/Async/Await and Normal Threads can handle both these cases, should be golden (I would think).