@@ -16,8 +16,8 @@ public class WampSessionClient<TMessage> : IWampSessionClientExtended,
1616 private static readonly AuthenticateExtraData EmptyAuthenticateDetails = new AuthenticateExtraData ( ) ;
1717 private readonly IWampServerProxy mServerProxy ;
1818 private TaskCompletionSource < bool > mOpenTask = new TaskCompletionSource < bool > ( ) ;
19+ private TaskCompletionSource < GoodbyeMessage > mCloseTask = new TaskCompletionSource < GoodbyeMessage > ( ) ;
1920 private readonly IWampFormatter < TMessage > mFormatter ;
20- private readonly object mLock = new object ( ) ;
2121 private bool mGoodbyeSent ;
2222 private readonly IWampClientAuthenticator mAuthenticator ;
2323 private HelloDetails mSentDetails ;
@@ -115,6 +115,11 @@ public void Goodbye(GoodbyeDetails details, string reason)
115115 {
116116 mServerProxy . Goodbye ( new GoodbyeDetails ( ) , WampErrors . GoodbyeAndOut ) ;
117117 }
118+ else
119+ {
120+ GoodbyeMessage message = new GoodbyeMessage ( ) { Details = details , Reason = reason } ;
121+ mCloseTask . SetResult ( message ) ;
122+ }
118123 }
119124
120125 TrySetCloseEventArgs ( SessionCloseType . Goodbye , details , reason ) ;
@@ -126,10 +131,11 @@ private void RaiseConnectionBroken()
126131
127132 WampSessionCloseEventArgs closeEventArgs = mCloseEventArgs ;
128133
129- SetOpenTaskErrorIfNeeded ( new WampConnectionBrokenException ( mCloseEventArgs ) ) ;
134+ SetTasksErrorsIfNeeded ( new WampConnectionBrokenException ( mCloseEventArgs ) ) ;
130135
131136 Interlocked . CompareExchange ( ref mIsConnected , 0 , 1 ) ;
132137 mOpenTask = new TaskCompletionSource < bool > ( ) ;
138+ mCloseTask = new TaskCompletionSource < GoodbyeMessage > ( ) ;
133139 mCloseEventArgs = null ;
134140
135141 OnConnectionBroken ( closeEventArgs ) ;
@@ -154,6 +160,8 @@ private void TrySetCloseEventArgs(SessionCloseType sessionCloseType,
154160
155161 public Task OpenTask => mOpenTask . Task ;
156162
163+ public Task < GoodbyeMessage > CloseTask => mCloseTask . Task ;
164+
157165 public void Close ( string reason , GoodbyeDetails details )
158166 {
159167 reason = reason ?? WampErrors . CloseNormal ;
@@ -191,19 +199,15 @@ public void OnConnectionClosed()
191199
192200 public void OnConnectionError ( Exception exception )
193201 {
194- SetOpenTaskErrorIfNeeded ( exception ) ;
202+ SetTasksErrorsIfNeeded ( exception ) ;
195203
196204 OnConnectionError ( new WampConnectionErrorEventArgs ( exception ) ) ;
197205 }
198206
199- private void SetOpenTaskErrorIfNeeded ( Exception exception )
207+ private void SetTasksErrorsIfNeeded ( Exception exception )
200208 {
201- TaskCompletionSource < bool > openTask = mOpenTask ;
202-
203- if ( openTask != null )
204- {
205- openTask . TrySetException ( exception ) ;
206- }
209+ mOpenTask ? . TrySetException ( exception ) ;
210+ mCloseTask ? . TrySetException ( exception ) ;
207211 }
208212
209213 public event EventHandler < WampSessionCreatedEventArgs > ConnectionEstablished ;
0 commit comments