| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Threading; |
| | 6 | |
|
| | 7 | | namespace Azure.Messaging.EventHubs.Core |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// The set of extensions for the <see cref="CancellationToken" /> |
| | 11 | | /// struct. |
| | 12 | | /// </summary> |
| | 13 | | /// |
| | 14 | | internal static class CancellationTokenExtensions |
| | 15 | | { |
| | 16 | | /// <summary> |
| | 17 | | /// Throws an exception of the requested type if cancellation has been requested |
| | 18 | | /// of the <paramref name="instance" />. |
| | 19 | | /// </summary> |
| | 20 | | /// |
| | 21 | | /// <typeparam name="T">The type of exception to throw; the type must have a parameterless constructor.</typepar |
| | 22 | | /// |
| | 23 | | /// <param name="instance">The instance that this method was invoked on.</param> |
| | 24 | | /// |
| | 25 | | public static void ThrowIfCancellationRequested<T>(this CancellationToken instance) where T : Exception, new() |
| | 26 | | { |
| 286 | 27 | | if (instance.IsCancellationRequested) |
| | 28 | | { |
| 18 | 29 | | throw new T(); |
| | 30 | | } |
| 268 | 31 | | } |
| | 32 | | } |
| | 33 | | } |