Skip to content

Commit c2f4c19

Browse files
committed
Simplify wrapper to take token from arg
1 parent b773196 commit c2f4c19

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

projects/RabbitMQ.Client/client/events/AsyncEventingBasicConsumer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ await base.OnCancelAsync(consumerTags, cancellationToken)
5858
.ConfigureAwait(false);
5959
if (!_unregisteredWrapper.IsEmpty)
6060
{
61-
await _unregisteredWrapper.InvokeAsync(this, new ConsumerEventArgs(consumerTags, cancellationToken), cancellationToken)
61+
await _unregisteredWrapper.InvokeAsync(this, new ConsumerEventArgs(consumerTags, cancellationToken))
6262
.ConfigureAwait(false);
6363
}
6464
}
@@ -70,7 +70,7 @@ await base.HandleBasicConsumeOkAsync(consumerTag, cancellationToken)
7070
.ConfigureAwait(false);
7171
if (!_registeredWrapper.IsEmpty)
7272
{
73-
await _registeredWrapper.InvokeAsync(this, new ConsumerEventArgs(new[] { consumerTag }, cancellationToken), cancellationToken)
73+
await _registeredWrapper.InvokeAsync(this, new ConsumerEventArgs(new[] { consumerTag }, cancellationToken))
7474
.ConfigureAwait(false);
7575
}
7676
}
@@ -82,7 +82,7 @@ public override Task HandleBasicDeliverAsync(string consumerTag, ulong deliveryT
8282
var deliverEventArgs = new BasicDeliverEventArgs(consumerTag, deliveryTag, redelivered, exchange, routingKey, properties, body, cancellationToken);
8383

8484
// No need to call base, it's empty.
85-
return _receivedWrapper.InvokeAsync(this, deliverEventArgs, cancellationToken);
85+
return _receivedWrapper.InvokeAsync(this, deliverEventArgs);
8686
}
8787

8888
///<summary>Fires the Shutdown event.</summary>
@@ -92,7 +92,7 @@ await base.HandleChannelShutdownAsync(channel, reason)
9292
.ConfigureAwait(false);
9393
if (!_shutdownWrapper.IsEmpty)
9494
{
95-
await _shutdownWrapper.InvokeAsync(this, reason, reason.CancellationToken)
95+
await _shutdownWrapper.InvokeAsync(this, reason)
9696
.ConfigureAwait(false);
9797
}
9898
}

projects/RabbitMQ.Client/client/impl/AsyncEventingWrapper.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
namespace RabbitMQ.Client.Impl
77
{
8-
internal struct AsyncEventingWrapper<T> where T : AsyncEventArgs
8+
internal struct AsyncEventingWrapper<TEvent> where TEvent : AsyncEventArgs
99
{
10-
private event AsyncEventHandler<T>? _event;
10+
private event AsyncEventHandler<TEvent>? _event;
1111
private Delegate[]? _handlers;
1212
private string? _context;
1313
private Func<Exception, string, CancellationToken, Task>? _onException;
@@ -22,20 +22,20 @@ public AsyncEventingWrapper(string context, Func<Exception, string, Cancellation
2222
_onException = onException;
2323
}
2424

25-
public void AddHandler(AsyncEventHandler<T>? handler)
25+
public void AddHandler(AsyncEventHandler<TEvent>? handler)
2626
{
2727
_event += handler;
2828
_handlers = null;
2929
}
3030

31-
public void RemoveHandler(AsyncEventHandler<T>? handler)
31+
public void RemoveHandler(AsyncEventHandler<TEvent>? handler)
3232
{
3333
_event -= handler;
3434
_handlers = null;
3535
}
3636

3737
// 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)
3939
{
4040
Delegate[]? handlers = _handlers;
4141
if (handlers is null)
@@ -49,23 +49,23 @@ public Task InvokeAsync(object sender, T parameter, CancellationToken cancellati
4949
_handlers = handlers;
5050
}
5151

52-
return InternalInvoke(handlers, sender, parameter, cancellationToken);
52+
return InternalInvoke(handlers, sender, parameter);
5353
}
5454

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)
5656
{
57-
foreach (AsyncEventHandler<T> action in handlers)
57+
foreach (AsyncEventHandler<TEvent> action in handlers)
5858
{
5959
try
6060
{
61-
await action(sender, parameter)
61+
await action(sender, @event)
6262
.ConfigureAwait(false);
6363
}
6464
catch (Exception exception)
6565
{
6666
if (_onException != null)
6767
{
68-
await _onException(exception, _context!, cancellationToken)
68+
await _onException(exception, _context!, @event.CancellationToken)
6969
.ConfigureAwait(false);
7070
}
7171
else
@@ -76,7 +76,7 @@ await _onException(exception, _context!, cancellationToken)
7676
}
7777
}
7878

79-
public void Takeover(in AsyncEventingWrapper<T> other)
79+
public void Takeover(in AsyncEventingWrapper<TEvent> other)
8080
{
8181
_event = other._event;
8282
_handlers = other._handlers;

0 commit comments

Comments
 (0)