File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,6 +37,8 @@ public abstract class EasyClient : IEasyClient
3737
3838 internal static readonly int DefaultSocketSenderPoolSize = 10 ;
3939
40+ private bool _continuousReceivingStarted = false ;
41+
4042 protected EasyClient ( )
4143 : this ( NullLogger . Instance )
4244 {
@@ -222,7 +224,9 @@ private void StartReceive()
222224 client . OnError ( "The receive task was cancelled." ) ;
223225 return ;
224226 }
225- } , this , TaskContinuationOptions . OnlyOnFaulted ) ; ;
227+ } , this , TaskContinuationOptions . OnlyOnFaulted ) ;
228+
229+ _continuousReceivingStarted = true ;
226230 }
227231
228232 protected abstract Task StartReceiveAsync ( ) ;
@@ -280,7 +284,17 @@ protected virtual async ValueTask SendAsync<TSendPackage>(IPackageEncoder<TSendP
280284
281285 public virtual async ValueTask CloseAsync ( )
282286 {
283- await Connection . CloseAsync ( CloseReason . LocalClosing ) ;
287+ var closeTask = Connection . CloseAsync ( CloseReason . LocalClosing ) ;
288+
289+ if ( _continuousReceivingStarted )
290+ {
291+ await closeTask ;
292+ }
293+ else
294+ {
295+ await Task . WhenAll ( closeTask . AsTask ( ) , StartReceiveAsync ( ) ) ;
296+ }
297+
284298 OnClosed ( this , EventArgs . Empty ) ;
285299 }
286300 }
You can’t perform that action at this time.
0 commit comments