[C#] Add cancel support for futures and streams#1580
[C#] Add cancel support for futures and streams#1580dicej merged 3 commits intobytecodealliance:mainfrom
Conversation
Clear up some debug use same package location for codegen and runtime tests.
dicej
left a comment
There was a problem hiding this comment.
While dotnet Task are cancelable via tokens, that is not the design we want for components
Can you elaborate on this? What makes CancellationToken a bad fit here?
crates/csharp/src/AsyncSupport.cs
Outdated
| } | ||
| else if (it.IsCanceled) | ||
| { | ||
| // readTask.SetCanceled(); |
There was a problem hiding this comment.
I'll delete this, we dont actually need to do anything in here, the cancellation is on the outer task. We do call Cancel on this inner task, but its just for correctness rather than anything functional.
| bufferHandle = lowerPayload(); | ||
|
|
||
| var status = new WaitableStatus(VTableWrite(bufferHandle == null ? IntPtr.Zero : bufferHandle.Value.AddrOfPinnedObject(), length)); | ||
| canDrop = true; // We can only call drop once something has been written. |
There was a problem hiding this comment.
We should set this back to false if the write is cancelled.
Its a cooperative mechanism: the long running task periodically checks the token to see if a cancellation has been requested, while typically another thread will issue the cancel on the token, We don't have a loop in C# where we could periodically check the cancellation status of the token. |
Make sure writables are not dropped after cancellation.
Co-authored-by: Joel Dice <joel.dice@akamai.com>
This PR adds some support for canceling futures and streams..While dotnet
Taskare cancelable via tokens, that is not the design we want for components, so in this PR there is introduced aComponentTaskwhich is a merging of aTaskand aTaskCompletionSource(and their generic counterparts) which adds aCancelmethod.In place of Rust's
Result<>this uses aComponentTaskResulttogether with aCancelCodeenum.LiftingTaskCompletionSourceis a placeholder for returning values from async functions. It requires the lifting code, but hopefully can be used as a starting point.Changes all task continuations to be
ExecuteSynchronouslyas we only have one thread, and this is more predicable. This should be removed if we get true multithreading.The
indexsuffix on imports is now created sequentially, no longer hard coded to0.Adds the runtime test,
future-cancel-read