Posted By

sai-venkat on 02/19/10


Tagged

ruby jruby clojure concurrency stm


Versions (?)

cloby.rb


 / Published in: Ruby
 

  1. require 'clojure'
  2.  
  3. class MyClojureObj < Clojure::Object
  4. def initialize
  5. dosync { @foo = 'foo' }
  6. end
  7.  
  8. attr_accessor :foo
  9. end
  10.  
  11. obj = MyClojureObj.new
  12. puts "obj.foo = " + obj.foo
  13.  
  14. begin
  15. puts "Setting obj.foo to 'bar'"
  16. obj.foo = 'bar'
  17. rescue ConcurrencyError
  18. puts "Oops, need a transaction"
  19. end
  20.  
  21. puts "Trying again with a transaction"
  22. dosync { obj.foo = 'bar' }
  23. puts "Success"
  24.  
  25. puts "obj.foo = " + obj.foo

Report this snippet  

You need to login to post a comment.