Cancel CTS immediately if delay is zero. (dotnet/coreclr#18098)
authorElliot Prior <1709938+Quogu@users.noreply.github.com>
Fri, 25 Jan 2019 13:59:30 +0000 (13:59 +0000)
committerStephen Toub <stoub@microsoft.com>
Fri, 25 Jan 2019 13:59:30 +0000 (08:59 -0500)
commit9ce935be82add5a1f17daa417e7d491208e19f03
tree566434411176fbd3d7e37afefda6cc04574938c9
parenta88f5b4ec1d4c81c6b3eacaefa5291583bc33162
Cancel CTS immediately if delay is zero. (dotnet/coreclr#18098)

The intended behaviour on specifying a delay of zero is that the CancellationTokenSource is cancelled immediately - before this change, it would depend on the scheduling of the timer callback which could lead to seeing a non-cancelled token. Now, it marks itself as cancelled immediately, without invoking any callbacks (as this method is called only from within the constructor of the object, before any callbacks could have been registered.

Commit migrated from https://github.com/dotnet/coreclr/commit/dcdfeea0b85b09e0f066fdfd05f5fef289977ab9
src/libraries/System.Private.CoreLib/src/System/Threading/CancellationTokenSource.cs