|
| 1 | +// This source code is dual-licensed under the Apache License, version |
| 2 | +// 2.0, and the Mozilla Public License, version 2.0. |
| 3 | +// |
| 4 | +// The APL v2.0: |
| 5 | +// |
| 6 | +//--------------------------------------------------------------------------- |
| 7 | +// Copyright (c) 2007-2024 Broadcom. All Rights Reserved. |
| 8 | +// |
| 9 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | +// you may not use this file except in compliance with the License. |
| 11 | +// You may obtain a copy of the License at |
| 12 | +// |
| 13 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 14 | +// |
| 15 | +// Unless required by applicable law or agreed to in writing, software |
| 16 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | +// See the License for the specific language governing permissions and |
| 19 | +// limitations under the License. |
| 20 | +//--------------------------------------------------------------------------- |
| 21 | +// |
| 22 | +// The MPL v2.0: |
| 23 | +// |
| 24 | +//--------------------------------------------------------------------------- |
| 25 | +// This Source Code Form is subject to the terms of the Mozilla Public |
| 26 | +// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 27 | +// file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 28 | +// |
| 29 | +// Copyright (c) 2007-2024 Broadcom. All Rights Reserved. |
| 30 | +//--------------------------------------------------------------------------- |
| 31 | + |
| 32 | +using System.Threading; |
| 33 | + |
| 34 | +namespace RabbitMQ.Client.Events |
| 35 | +{ |
| 36 | + /// <summary> |
| 37 | + /// Provides data for <see cref="AsyncEventHandler{T}"/> |
| 38 | + /// events that can be invoked asynchronously. |
| 39 | + /// </summary> |
| 40 | + public class AsyncEventArgs |
| 41 | + { |
| 42 | + /// <summary> |
| 43 | + /// Initializes a new instance of the <see cref="AsyncEventArgs"/> |
| 44 | + /// class. |
| 45 | + /// </summary> |
| 46 | + /// <param name="cancellationToken"> |
| 47 | + /// A cancellation token related to the original operation that raised |
| 48 | + /// the event. It's important for your handler to pass this token |
| 49 | + /// along to any asynchronous or long-running synchronous operations |
| 50 | + /// that take a token so cancellation will correctly propagate. The |
| 51 | + /// default value is <see cref="CancellationToken.None"/>. |
| 52 | + /// </param> |
| 53 | + public AsyncEventArgs(CancellationToken cancellationToken = default) |
| 54 | + { |
| 55 | + CancellationToken = cancellationToken; |
| 56 | + } |
| 57 | + |
| 58 | + /// <summary> |
| 59 | + /// Gets a cancellation token related to the original operation that |
| 60 | + /// raised the event. It's important for your handler to pass this |
| 61 | + /// token along to any asynchronous or long-running synchronous |
| 62 | + /// operations that take a token so cancellation (via something like |
| 63 | + /// <code> |
| 64 | + /// new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token |
| 65 | + /// </code> |
| 66 | + /// for example) will correctly propagate. |
| 67 | + /// </summary> |
| 68 | + public CancellationToken CancellationToken { get; } |
| 69 | + |
| 70 | + /// <summary> |
| 71 | + /// Provides a value to use with events that do not have event data. |
| 72 | + /// </summary> |
| 73 | + public static readonly AsyncEventArgs Empty = new AsyncEventArgs(); |
| 74 | + } |
| 75 | +} |
0 commit comments