@@ -17,6 +17,7 @@ public class WampChannelReconnector : IDisposable
1717 private IDisposable mDisposable = Disposable . Empty ;
1818 private bool mStarted = false ;
1919 private readonly object mLock = new object ( ) ;
20+ private IDisposable mConnectionBrokenDisposable ;
2021
2122 /// <summary>
2223 /// Initializes a new instance of <see cref="WampChannelReconnector"/>.
@@ -29,20 +30,22 @@ public WampChannelReconnector(IWampChannel channel, Func<Task> connector)
2930
3031 var connectionBrokenObservable =
3132 Observable . FromEventPattern < WampSessionCloseEventArgs >
32- ( x => monitor . ConnectionBroken += x ,
33- x => monitor . ConnectionBroken -= x )
34- . Select ( x => Unit . Default ) ;
33+ ( x => monitor . ConnectionBroken += x ,
34+ x => monitor . ConnectionBroken -= x )
35+ . Select ( x => Unit . Default )
36+ . Replay ( 1 ) ;
3537
3638 var onceAndConnectionBroken =
37- Observable . Return ( Unit . Default ) . Concat
38- ( connectionBrokenObservable ) ;
39+ connectionBrokenObservable . StartWith ( Unit . Default ) ;
3940
4041 IObservable < IObservable < Unit > > reconnect =
4142 from connectionBroke in onceAndConnectionBroken
4243 let tryReconnect = Observable . FromAsync ( connector )
4344 . Catch < Unit , Exception > ( x => Observable . Empty < Unit > ( ) )
4445 select tryReconnect ;
4546
47+ mConnectionBrokenDisposable = connectionBrokenObservable . Connect ( ) ;
48+
4649 mMerged = reconnect . Concat ( ) ;
4750 }
4851
@@ -78,6 +81,7 @@ public void Dispose()
7881 {
7982 mMerged = null ;
8083 mDisposable . Dispose ( ) ;
84+ mConnectionBrokenDisposable . Dispose ( ) ;
8185 }
8286 }
8387 }
0 commit comments