Closed
Description
Hi,
I'm looking at Subscription.scala because I'm doing the Coursera Reactive course.
The code below from Subscription.scala looks a bit suspect. I think there's a race condition that will happen especially if u takes a long time that could lead to multiple calls to u. I'm not sure if you consider this an issue as I am not sure if Subscriptions are shared across threads, but the use of the AtomicBoolean seems to imply this.
Would something like:
def unsubscribe() { if(unsubscribed.compareAndSet(false, true)) { u }}
be better - also looks like subclasses eg. BooleanSubscription may have this problem.
If you think this is an issue I can look to fix.
Regards
Mick
def apply(u: => Unit): Subscription = {
new Subscription() {
private val unsubscribed = new AtomicBoolean(false)
def isUnsubscribed = unsubscribed.get()
val asJavaSubscription = new rx.Subscription {
def unsubscribe() { if(!unsubscribed.get()) { u ; unsubscribed.set(true) }}
}
}
}
Metadata
Metadata
Assignees
Labels
No labels