@@ -181,29 +181,6 @@ public IAsyncBasicConsumer? DefaultConsumer
181
181
[ MemberNotNullWhen ( false , nameof ( CloseReason ) ) ]
182
182
public bool IsOpen => CloseReason is null ;
183
183
184
- public ulong NextPublishSeqNo
185
- {
186
- get
187
- {
188
- if ( ConfirmsAreEnabled )
189
- {
190
- _confirmSemaphore . Wait ( ) ;
191
- try
192
- {
193
- return _nextPublishSeqNo ;
194
- }
195
- finally
196
- {
197
- _confirmSemaphore . Release ( ) ;
198
- }
199
- }
200
- else
201
- {
202
- return _nextPublishSeqNo ;
203
- }
204
- }
205
- }
206
-
207
184
public string ? CurrentQueue { get ; private set ; }
208
185
209
186
public ISession Session { get ; private set ; }
@@ -589,7 +566,7 @@ public Task ConnectionTuneOkAsync(ushort channelMax, uint frameMax, ushort heart
589
566
return ModelSendAsync ( method , cancellationToken ) . AsTask ( ) ;
590
567
}
591
568
592
- protected void HandleBasicAck ( IncomingCommand cmd )
569
+ protected async Task < bool > HandleBasicAck ( IncomingCommand cmd , CancellationToken cancellationToken )
593
570
{
594
571
var ack = new BasicAck ( cmd . MethodSpan ) ;
595
572
if ( ! _basicAcksWrapper . IsEmpty )
@@ -598,10 +575,12 @@ protected void HandleBasicAck(IncomingCommand cmd)
598
575
_basicAcksWrapper . Invoke ( this , args ) ;
599
576
}
600
577
601
- HandleAckNack ( ack . _deliveryTag , ack . _multiple , false ) ;
578
+ await HandleAckNack ( ack . _deliveryTag , ack . _multiple , false , cancellationToken )
579
+ . ConfigureAwait ( false ) ;
580
+ return true ;
602
581
}
603
582
604
- protected void HandleBasicNack ( IncomingCommand cmd )
583
+ protected async Task < bool > HandleBasicNack ( IncomingCommand cmd , CancellationToken cancellationToken )
605
584
{
606
585
var nack = new BasicNack ( cmd . MethodSpan ) ;
607
586
if ( ! _basicNacksWrapper . IsEmpty )
@@ -611,7 +590,9 @@ protected void HandleBasicNack(IncomingCommand cmd)
611
590
_basicNacksWrapper . Invoke ( this , args ) ;
612
591
}
613
592
614
- HandleAckNack ( nack . _deliveryTag , nack . _multiple , true ) ;
593
+ await HandleAckNack ( nack . _deliveryTag , nack . _multiple , true , cancellationToken )
594
+ . ConfigureAwait ( false ) ;
595
+ return true ;
615
596
}
616
597
617
598
protected async Task < bool > HandleBasicCancelAsync ( IncomingCommand cmd , CancellationToken cancellationToken )
@@ -801,6 +782,26 @@ protected void HandleConnectionUnblocked()
801
782
Session . Connection . HandleConnectionUnblocked ( ) ;
802
783
}
803
784
785
+ public async ValueTask < ulong > GetNextPublishSequenceNumberAsync ( CancellationToken cancellationToken = default )
786
+ {
787
+ if ( ConfirmsAreEnabled )
788
+ {
789
+ await _confirmSemaphore . WaitAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
790
+ try
791
+ {
792
+ return _nextPublishSeqNo ;
793
+ }
794
+ finally
795
+ {
796
+ _confirmSemaphore . Release ( ) ;
797
+ }
798
+ }
799
+ else
800
+ {
801
+ return _nextPublishSeqNo ;
802
+ }
803
+ }
804
+
804
805
public abstract ValueTask BasicAckAsync ( ulong deliveryTag , bool multiple ,
805
806
CancellationToken cancellationToken ) ;
806
807
@@ -1829,7 +1830,7 @@ await tokenRegistration.DisposeAsync()
1829
1830
1830
1831
// NOTE: this method is internal for its use in this test:
1831
1832
// TestWaitForConfirmsWithTimeoutAsync_MessageNacked_WaitingHasTimedout_ReturnFalse
1832
- internal void HandleAckNack ( ulong deliveryTag , bool multiple , bool isNack )
1833
+ internal async Task HandleAckNack ( ulong deliveryTag , bool multiple , bool isNack , CancellationToken cancellationToken = default )
1833
1834
{
1834
1835
// Only do this if confirms are enabled *and* the library is tracking confirmations
1835
1836
if ( ConfirmsAreEnabled && _trackConfirmations )
@@ -1839,7 +1840,8 @@ internal void HandleAckNack(ulong deliveryTag, bool multiple, bool isNack)
1839
1840
throw new InvalidOperationException ( InternalConstants . BugFound ) ;
1840
1841
}
1841
1842
// let's take a lock so we can assume that deliveryTags are unique, never duplicated and always sorted
1842
- _confirmSemaphore . Wait ( ) ;
1843
+ await _confirmSemaphore . WaitAsync ( cancellationToken )
1844
+ . ConfigureAwait ( false ) ;
1843
1845
try
1844
1846
{
1845
1847
// No need to do anything if there are no delivery tags in the list
0 commit comments