@@ -181,29 +181,6 @@ public IAsyncBasicConsumer? DefaultConsumer
181181 [ MemberNotNullWhen ( false , nameof ( CloseReason ) ) ]
182182 public bool IsOpen => CloseReason is null ;
183183
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-
207184 public string ? CurrentQueue { get ; private set ; }
208185
209186 public ISession Session { get ; private set ; }
@@ -589,7 +566,7 @@ public Task ConnectionTuneOkAsync(ushort channelMax, uint frameMax, ushort heart
589566 return ModelSendAsync ( method , cancellationToken ) . AsTask ( ) ;
590567 }
591568
592- protected void HandleBasicAck ( IncomingCommand cmd )
569+ protected async Task < bool > HandleBasicAck ( IncomingCommand cmd , CancellationToken cancellationToken )
593570 {
594571 var ack = new BasicAck ( cmd . MethodSpan ) ;
595572 if ( ! _basicAcksWrapper . IsEmpty )
@@ -598,10 +575,12 @@ protected void HandleBasicAck(IncomingCommand cmd)
598575 _basicAcksWrapper . Invoke ( this , args ) ;
599576 }
600577
601- HandleAckNack ( ack . _deliveryTag , ack . _multiple , false ) ;
578+ await HandleAckNack ( ack . _deliveryTag , ack . _multiple , false , cancellationToken )
579+ . ConfigureAwait ( false ) ;
580+ return true ;
602581 }
603582
604- protected void HandleBasicNack ( IncomingCommand cmd )
583+ protected async Task < bool > HandleBasicNack ( IncomingCommand cmd , CancellationToken cancellationToken )
605584 {
606585 var nack = new BasicNack ( cmd . MethodSpan ) ;
607586 if ( ! _basicNacksWrapper . IsEmpty )
@@ -611,7 +590,9 @@ protected void HandleBasicNack(IncomingCommand cmd)
611590 _basicNacksWrapper . Invoke ( this , args ) ;
612591 }
613592
614- HandleAckNack ( nack . _deliveryTag , nack . _multiple , true ) ;
593+ await HandleAckNack ( nack . _deliveryTag , nack . _multiple , true , cancellationToken )
594+ . ConfigureAwait ( false ) ;
595+ return true ;
615596 }
616597
617598 protected async Task < bool > HandleBasicCancelAsync ( IncomingCommand cmd , CancellationToken cancellationToken )
@@ -801,6 +782,26 @@ protected void HandleConnectionUnblocked()
801782 Session . Connection . HandleConnectionUnblocked ( ) ;
802783 }
803784
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+
804805 public abstract ValueTask BasicAckAsync ( ulong deliveryTag , bool multiple ,
805806 CancellationToken cancellationToken ) ;
806807
@@ -1829,7 +1830,7 @@ await tokenRegistration.DisposeAsync()
18291830
18301831 // NOTE: this method is internal for its use in this test:
18311832 // 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 )
18331834 {
18341835 // Only do this if confirms are enabled *and* the library is tracking confirmations
18351836 if ( ConfirmsAreEnabled && _trackConfirmations )
@@ -1839,7 +1840,8 @@ internal void HandleAckNack(ulong deliveryTag, bool multiple, bool isNack)
18391840 throw new InvalidOperationException ( InternalConstants . BugFound ) ;
18401841 }
18411842 // 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 ) ;
18431845 try
18441846 {
18451847 // No need to do anything if there are no delivery tags in the list
0 commit comments