Created
January 21, 2014 17:58
-
-
Save Sciss/8544824 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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