@@ -75,19 +75,20 @@ public Task StartAsync(CancellationToken stopCancellationToken)
7575
7676 try
7777 {
78- await foreach ( var context in _messagesBuffer . Reader . ReadAllItemsAsync ( stopCancellationToken ) )
78+ await foreach ( var context in _messagesBuffer . Reader . ReadAllItemsAsync ( stopCancellationToken ) . ConfigureAwait ( false ) )
7979 {
8080 currentContext = context ;
8181
8282 await this
8383 . ProcessMessageAsync ( context , stopCancellationToken )
84- . WithCancellation ( stopCancellationToken , true ) ;
84+ . WithCancellation ( stopCancellationToken , true )
85+ . ConfigureAwait ( false ) ;
8586 }
8687 }
8788 catch ( OperationCanceledException )
8889 {
8990 currentContext ? . ConsumerContext . Discard ( ) ;
90- await this . DiscardBufferedContextsAsync ( ) ;
91+ await this . DiscardBufferedContextsAsync ( ) . ConfigureAwait ( false ) ;
9192 }
9293 catch ( Exception ex )
9394 {
@@ -101,13 +102,13 @@ await this
101102
102103 public async Task StopAsync ( )
103104 {
104- await _workerStoppingEvent . FireAsync ( ) ;
105+ await _workerStoppingEvent . FireAsync ( ) . ConfigureAwait ( false ) ;
105106
106107 _messagesBuffer . Writer . TryComplete ( ) ;
107108
108- await _backgroundTask ;
109+ await _backgroundTask . ConfigureAwait ( false ) ;
109110
110- await _workerStoppedEvent . FireAsync ( ) ;
111+ await _workerStoppedEvent . FireAsync ( ) . ConfigureAwait ( false ) ;
111112 }
112113
113114 public void Dispose ( )
@@ -118,7 +119,7 @@ public void Dispose()
118119
119120 private async Task DiscardBufferedContextsAsync ( )
120121 {
121- await foreach ( var context in _messagesBuffer . Reader . ReadAllItemsAsync ( CancellationToken . None ) )
122+ await foreach ( var context in _messagesBuffer . Reader . ReadAllItemsAsync ( CancellationToken . None ) . ConfigureAwait ( false ) )
122123 {
123124 context . ConsumerContext . Discard ( ) ;
124125 }
@@ -130,29 +131,29 @@ private async Task ProcessMessageAsync(IMessageContext context, CancellationToke
130131 {
131132 try
132133 {
133- await _globalEvents . FireMessageConsumeStartedAsync ( new MessageEventContext ( context ) ) ;
134+ await _globalEvents . FireMessageConsumeStartedAsync ( new MessageEventContext ( context ) ) . ConfigureAwait ( false ) ;
134135
135136 _ = context . ConsumerContext . Completion . ContinueWith (
136137 async task =>
137138 {
138139 if ( task . IsFaulted )
139140 {
140- await _globalEvents . FireMessageConsumeErrorAsync ( new MessageErrorEventContext ( context , task . Exception ) ) ;
141+ await _globalEvents . FireMessageConsumeErrorAsync ( new MessageErrorEventContext ( context , task . Exception ) ) . ConfigureAwait ( false ) ;
141142 }
142143
143- await _globalEvents . FireMessageConsumeCompletedAsync ( new MessageEventContext ( context ) ) ;
144+ await _globalEvents . FireMessageConsumeCompletedAsync ( new MessageEventContext ( context ) ) . ConfigureAwait ( false ) ;
144145 } ,
145146 CancellationToken . None ) ;
146147
147- await _middlewareExecutor . Execute ( context , _ => Task . CompletedTask ) ;
148+ await _middlewareExecutor . Execute ( context , _ => Task . CompletedTask ) . ConfigureAwait ( false ) ;
148149 }
149150 catch ( OperationCanceledException ) when ( cancellationToken . IsCancellationRequested )
150151 {
151152 context . ConsumerContext . ShouldStoreOffset = false ;
152153 }
153154 catch ( Exception ex )
154155 {
155- await _globalEvents . FireMessageConsumeErrorAsync ( new MessageErrorEventContext ( context , ex ) ) ;
156+ await _globalEvents . FireMessageConsumeErrorAsync ( new MessageErrorEventContext ( context , ex ) ) . ConfigureAwait ( false ) ;
156157
157158 _logHandler . Error (
158159 "Error processing message" ,
@@ -172,7 +173,7 @@ private async Task ProcessMessageAsync(IMessageContext context, CancellationToke
172173 context . ConsumerContext . Complete ( ) ;
173174 }
174175
175- await _workerProcessingEnded . FireAsync ( context ) ;
176+ await _workerProcessingEnded . FireAsync ( context ) . ConfigureAwait ( false ) ;
176177 }
177178 }
178179 catch ( Exception ex )
0 commit comments