5
5
6
6
namespace RabbitMQ . Client . Impl
7
7
{
8
- internal struct AsyncEventingWrapper < T > where T : AsyncEventArgs
8
+ internal struct AsyncEventingWrapper < TEvent > where TEvent : AsyncEventArgs
9
9
{
10
- private event AsyncEventHandler < T > ? _event ;
10
+ private event AsyncEventHandler < TEvent > ? _event ;
11
11
private Delegate [ ] ? _handlers ;
12
12
private string ? _context ;
13
13
private Func < Exception , string , CancellationToken , Task > ? _onException ;
@@ -22,20 +22,20 @@ public AsyncEventingWrapper(string context, Func<Exception, string, Cancellation
22
22
_onException = onException ;
23
23
}
24
24
25
- public void AddHandler ( AsyncEventHandler < T > ? handler )
25
+ public void AddHandler ( AsyncEventHandler < TEvent > ? handler )
26
26
{
27
27
_event += handler ;
28
28
_handlers = null ;
29
29
}
30
30
31
- public void RemoveHandler ( AsyncEventHandler < T > ? handler )
31
+ public void RemoveHandler ( AsyncEventHandler < TEvent > ? handler )
32
32
{
33
33
_event -= handler ;
34
34
_handlers = null ;
35
35
}
36
36
37
37
// Do not make this function async! (This type is a struct that gets copied at the start of an async method => empty _handlers is copied)
38
- public Task InvokeAsync ( object sender , T parameter , CancellationToken cancellationToken = default )
38
+ public Task InvokeAsync ( object sender , TEvent parameter )
39
39
{
40
40
Delegate [ ] ? handlers = _handlers ;
41
41
if ( handlers is null )
@@ -49,23 +49,23 @@ public Task InvokeAsync(object sender, T parameter, CancellationToken cancellati
49
49
_handlers = handlers ;
50
50
}
51
51
52
- return InternalInvoke ( handlers , sender , parameter , cancellationToken ) ;
52
+ return InternalInvoke ( handlers , sender , parameter ) ;
53
53
}
54
54
55
- private readonly async Task InternalInvoke ( Delegate [ ] handlers , object sender , T parameter , CancellationToken cancellationToken )
55
+ private readonly async Task InternalInvoke ( Delegate [ ] handlers , object sender , TEvent @event )
56
56
{
57
- foreach ( AsyncEventHandler < T > action in handlers )
57
+ foreach ( AsyncEventHandler < TEvent > action in handlers )
58
58
{
59
59
try
60
60
{
61
- await action ( sender , parameter )
61
+ await action ( sender , @event )
62
62
. ConfigureAwait ( false ) ;
63
63
}
64
64
catch ( Exception exception )
65
65
{
66
66
if ( _onException != null )
67
67
{
68
- await _onException ( exception , _context ! , cancellationToken )
68
+ await _onException ( exception , _context ! , @event . CancellationToken )
69
69
. ConfigureAwait ( false ) ;
70
70
}
71
71
else
@@ -76,7 +76,7 @@ await _onException(exception, _context!, cancellationToken)
76
76
}
77
77
}
78
78
79
- public void Takeover ( in AsyncEventingWrapper < T > other )
79
+ public void Takeover ( in AsyncEventingWrapper < TEvent > other )
80
80
{
81
81
_event = other . _event ;
82
82
_handlers = other . _handlers ;
0 commit comments