Skip to content

Instantly share code, notes, and snippets.

@Sciss
Created January 21, 2014 17:58
Show Gist options
  • Save Sciss/8544824 to your computer and use it in GitHub Desktop.
Save Sciss/8544824 to your computer and use it in GitHub Desktop.
object STMRollbackTest extends App {
import scala.concurrent.stm._
val r = Ref(0)
def trouble() = atomic { implicit tx =>
println("a: " + r())
r() = 2
println("b: " + r())
Txn.afterRollback { status =>
println(s"ROLLBACK $status")
}
throw new Exception()
}
def a() = {
println("A")
atomic { implicit tx =>
println("A ATOMIC")
r() = 1
val res = try {
println("TROUBLE:")
trouble()
} catch { case e: Exception =>
println("CATCH")
r()
}
println("RES")
res
}
}
println("c: " + a())
/* observed output:
A
A ATOMIC
TROUBLE:
a: 1
b: 2
ROLLBACK RolledBack(OptimisticFailureCause('restart_to_enable_partial_rollback,Some(java.lang.Exception)))
A ATOMIC
TROUBLE:
a: 1
b: 2
ROLLBACK RolledBack(UncaughtExceptionCause(java.lang.Exception))
CATCH
RES
c: 1
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment