@@ -93,13 +93,18 @@ object Finite {
9393 override protected [signals3] def onWire (): Unit =
9494 if (! first.isClosed) {
9595 first.subscribe(this )
96- first.onClose { second.subscribe(this ) }
96+ first.onClose {
97+ second.subscribe(this )
98+ first.unsubscribe(this )
99+ }
97100 } else {
98101 second.subscribe(this )
99102 }
100103
101- override protected [signals3] def onUnwire (): Unit =
102- if (! first.isClosed) first.unsubscribe(this ) else second.unsubscribe(this )
104+ override protected [signals3] def onUnwire (): Unit = {
105+ first.unsubscribe(this )
106+ second.unsubscribe(this )
107+ }
103108
104109 private def computeValue (current : Option [V ]): Option [V ] =
105110 if (! first.isClosed && current != first.value) first.value
@@ -115,13 +120,18 @@ object Finite {
115120 override protected [signals3] def onWire (): Unit =
116121 if (! first.isClosed) {
117122 first.subscribe(this )
118- first.onClose { second.subscribe(this ) }
123+ first.onClose {
124+ second.subscribe(this )
125+ first.unsubscribe(this )
126+ }
119127 } else {
120128 second.subscribe(this )
121129 }
122130
123- override protected [signals3] def onUnwire (): Unit =
124- if (! first.isClosed) first.unsubscribe(this ) else second.unsubscribe(this )
131+ override protected [signals3] def onUnwire (): Unit = {
132+ first.unsubscribe(this )
133+ second.unsubscribe(this )
134+ }
125135
126136 override protected [signals3] def onEvent (event : E , currentContext : Option [ExecutionContext ]): Unit =
127137 dispatch(event, currentContext)
@@ -132,8 +142,9 @@ object Finite {
132142
133143 private inline def switchToSecond (): Unit = {
134144 second.subscribe(this )
145+ first.unsubscribe(this )
135146 lastPromise.foreach(_.completeWith(second.last))
136- second.onClose {close()}
147+ second.onClose { close() }
137148 }
138149
139150 override protected [signals3] def onWire (): Unit =
@@ -160,8 +171,9 @@ object Finite {
160171 extends Stream [E ] with Finite [E ] with EventSubscriber [E ]{
161172 private inline def switchToSecond (): Unit = {
162173 second.subscribe(this )
174+ first.unsubscribe(this )
163175 lastPromise.foreach(_.completeWith(second.last))
164- second.onClose {close()}
176+ second.onClose { close() }
165177 }
166178
167179 override protected [signals3] def onWire (): Unit =
@@ -172,8 +184,10 @@ object Finite {
172184 switchToSecond()
173185 }
174186
175- override protected [signals3] def onUnwire (): Unit =
176- if (! first.isClosed) first.unsubscribe(this ) else if (! second.isClosed) second.unsubscribe(this )
187+ override protected [signals3] def onUnwire (): Unit = {
188+ first.unsubscribe(this )
189+ second.unsubscribe(this )
190+ }
177191
178192 override protected [signals3] def onEvent (event : E , currentContext : Option [ExecutionContext ]): Unit =
179193 if (! isClosed) dispatch(event, currentContext)
0 commit comments