- Adds the type, almost an exact copy of `TaskCompletionSource<TResult>`, but creating a `Task` instead of a `Task<TResult>`. Primary benefits here are symmetry, smaller `Task` object, and not forcing a developer to specify an unnecessary type name.
- Adds tests for both TCS and TCS<TResult>.
- Switches a bunch of usage of the generic type over to the non-generic, both in src and tests.
* Add TaskCompletionSource.SetCanceled(CancellationToken)
api-approved by #30862
* Add to ref
* SetCanceled(default)
* Change some tests to use SetCaneled not TrySetCanceled
These tests used SetResult/SetException and TrySetCancelled so it could
pass a token. Changed to use SetCancelled to match the Result/Exception
useage.
* Add SetCanceled(CT) test
* Check exception on re-cancel
* Equal not Equals
* Catch aggregate not TaskCancelled directly
* Inner not exc
* Markup
* s/m/n
Mechanical/automated change. The only manual changes were a) removing the two rules from the CodeAnalysis.ruleset file, b) removing spaces from one line of a .targets file that is used to generate a .cs file, and c) reverting the changes in a few test files where the naive replacement happened in the middle of a verbatim string where the whitespace actually mattered.
Commit migrated from https://github.com/dotnet/corefx/commit/09a6e66b0c2b31bd0f6e7e3170537d14027aeed0
This fixes a small behavioral difference between the mscorlib implementation of Unwrap and the corefx implementation of unwrap. A Task can end in a canceled state but contain a CancellationToken that doesn't have cancellation requested, e.g. if TaskCompletionSource.SetCanceled() is used. When Unwrap proxies such a task, the mscorlib implementation was appropriately reflecting that no-cancellation-requested state, whereas our corefx implementation was pretending it did have cancellation requested.
This commit fixes the corefx implementation to match, and adds a few additional test cases to verify.
Commit migrated from https://github.com/dotnet/corefx/commit/dcfa285452deebbb71e88d05b8180d193eb82c30
In strange but possible task configurations, it's possible to set up a series of Unwrap calls such that the continuations involved will form a very long chain of synchronously-executing calls. In such cases, without extra measure, the implementation can overflow the stack. The mscorlib Unwrap implementation takes precautions to avoid this, and ContinueWith (which was used in the previous, slower, standalone Unwrap implementation) has checks to avoid this as well, but currently await does not. Since our new Unwrap implementation uses the await infrastructure, it's susceptible again.
This commit adds a check to the new Unwrap implementation to avoid the stack dive, as well as porting a test that triggers the stack dive prior to the fix. Some local benchmarks show little-to-no impact from the additional checks, and it's very rare to hit the fallback path that triggers the async queueing: while the actual numbers will depend on the actual code being run, the size of stack frames, etc., in the test we only hit the fallback case ~8 times out of 12000 iterations, and that's in code trying very hard to force this condition.
Commit migrated from https://github.com/dotnet/corefx/commit/68633d3efa10a43a0650a11af078fddaa8aafa46
This commit provides a System.Threading.Tasks.Tests project that doesn't include all of the tests that @mellinoe is porting. However, it does include a new set of tests written from scratch for TaskExtensions.Unwrap, which is the portion of System.Threading.Tasks whose source lives in corefx rather than in coreclr. They are meant to be the primary unit testing for Unwrap, as the existing tests only superficially exercise the functionality.
Commit migrated from https://github.com/dotnet/corefx/commit/e7eeb95167babb03f2a149a0b95833efb9ba181a