Skip to content

Commit 748908a

Browse files
committed
Got framework and tests to compile with new exception refactoring.
1 parent 4ffd615 commit 748908a

25 files changed

+378
-239
lines changed

src/main/scala/scala/reactive/Channel.scala

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,25 @@ trait Channel[@spec(Int, Long, Double) T] {
6464

6565
/** Checks if this channel was terminated.
6666
*
67-
* A channel is terminated if it is sealed and all its reactives are unreacted.
67+
* A channel is terminated if it is sealed and all its reactives are
68+
* unreacted.
6869
*
6970
* @return `true` if the channel is terminated, `false` otherwise
7071
*/
7172
def isTerminated: Boolean
7273

7374
/** Composes this channel with a custom mapping function for the input events.
7475
*
75-
* Events from reactives passed to this channel are mapped inside their isolates.
76+
* Events from reactives passed to this channel are mapped inside their
77+
* isolates.
7678
*
7779
* @tparam S type of the events the new channel will accept
78-
* @param f maps events in the resulting channel to events of the original channel
80+
* @param f maps events in the resulting channel to events of the
81+
* original channel
7982
* @return the new channel accepting events of type `S`
8083
*/
81-
def compose[@spec(Int, Long, Double) S](f: S => T) = new Channel.Composed(this, f)
84+
def compose[@spec(Int, Long, Double) S](f: S => T) =
85+
new Channel.Composed(this, f)
8286

8387
/** Creates and attaches a reactive emitter to the channel.
8488
*
@@ -141,7 +145,8 @@ trait Channel[@spec(Int, Long, Double) T] {
141145
*/
142146
object Channel {
143147

144-
private[reactive] class Composed[@spec(Int, Long, Double) T, @spec(Int, Long, Double) S]
148+
private[reactive] class Composed
149+
[@spec(Int, Long, Double) T, @spec(Int, Long, Double) S]
145150
(val self: Channel[T], val f: S => T)
146151
extends Channel[S] {
147152
def attach(r: Reactive[S]): Channel[S] = {
@@ -164,14 +169,16 @@ object Channel {
164169
* @param reactor the reactor notified of this channel's events
165170
* @param monitor private monitor object used for synchronization
166171
*/
167-
class Synced[@spec(Int, Long, Double) T](val reactor: Reactor[T], val monitor: util.Monitor)
172+
class Synced[@spec(Int, Long, Double) T]
173+
(val reactor: Reactor[T], val monitor: util.Monitor)
168174
extends Channel[T] {
169175
private var sealedChannel = false
170176
private val reactives = mutable.Map[Reactive[T], Reactive.Subscription]()
171177
def attach(r: Reactive[T]) = monitor.synchronized {
172178
if (!sealedChannel) {
173179
if (!reactives.contains(r)) reactives(r) = r.observe(new Reactor[T] {
174180
def react(event: T) = reactor.react(event)
181+
def except(t: Throwable) = reactor.except(t)
175182
def unreact() {
176183
monitor.synchronized { reactives.remove(r) }
177184
checkTerminated()

src/main/scala/scala/reactive/RPair.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ trait RPair[@spec(Int, Long, Double) P, Q <: AnyRef] {
177177
try mutation(asSignal)
178178
catch {
179179
case t if isNonLethal(t) =>
180-
mutable.except(t)
180+
mutable.exception(t)
181181
}
182-
mutable.react()
182+
mutable.mutation()
183183
}
184184
}
185185

src/main/scala/scala/reactive/RValPair.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ trait RValPair[@spec(Int, Long, Double) P, @spec(Int, Long, Double) Q] {
133133
try mutation(asSignal)
134134
catch {
135135
case t if isNonLethal(t) =>
136-
mutable.except(t)
136+
mutable.exception(t)
137137
}
138-
mutable.react()
138+
mutable.mutation()
139139
}
140140
}
141141

src/main/scala/scala/reactive/ReactMutable.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ trait ReactMutable {
1818
/** Called internally - when the mutable reactive or its internal value has
1919
* been mutated.
2020
*/
21-
def react(): Unit
21+
def mutation(): Unit
2222

23-
def except(t: Throwable): Unit
23+
/** Called when an exception occurs during mutation.
24+
* Some reactive mutables may propagate the exception further.
25+
*/
26+
def exception(t: Throwable): Unit
2427

2528
}
2629

src/main/scala/scala/reactive/Reactive.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,8 @@ trait Reactive[@spec(Int, Long, Double) +T] {
427427
rm
428428
}
429429

430-
private def mutablesCompositeSubscription[M <: ReactMutable](
431-
mutables: Seq[M], selfsub: Reactive.Subscription) = {
430+
private def mutablesCompositeSubscription[M <: ReactMutable]
431+
(mutables: Seq[M], selfsub: Reactive.Subscription) = {
432432
for (m <- mutables) yield m.bindSubscription(selfsub)
433433
}
434434

@@ -1248,10 +1248,10 @@ object Reactive {
12481248
except(t)
12491249
// note: still need to mutate, just in case
12501250
}
1251-
mutable.react()
1251+
mutable.mutation()
12521252
}
12531253
def except(t: Throwable) {
1254-
mutable.except(t)
1254+
mutable.exception(t)
12551255
}
12561256
def unreact() {}
12571257
var subscription = Subscription.empty
@@ -1266,13 +1266,13 @@ object Reactive {
12661266
mutation(value)
12671267
} catch {
12681268
case t if isNonLethal(t) =>
1269-
except(t)
1269+
exception(t)
12701270
// note: still need to mutate, just in case
12711271
}
1272-
for (m <- mutables) m.react()
1272+
for (m <- mutables) m.mutation()
12731273
}
12741274
def except(t: Throwable) {
1275-
for (m <- mutables) m.except(t)
1275+
for (m <- mutables) m.exception(t)
12761276
}
12771277
def unreact() {}
12781278
var subscription = Subscription.empty

0 commit comments

Comments
 (0)