Skip to content

Instantly share code, notes, and snippets.

Created December 9, 2010 02:00
Show Gist options
  • Save anonymous/734222 to your computer and use it in GitHub Desktop.
Save anonymous/734222 to your computer and use it in GitHub Desktop.
~/projects/cloby ➔ cat examples/simple.rb
require 'cloby'
class MyClojureObj < Clojure::Object
def initialize
dosync { @foo = 'foo' }
end
attr_accessor :foo
end
obj = MyClojureObj.new
puts "obj.foo = " + obj.foo
begin
puts "Setting obj.foo to 'bar'"
obj.foo = 'bar'
rescue ConcurrencyError
puts "Oops, need a transaction"
end
puts "Trying again with a transaction"
dosync { obj.foo = 'bar' }
puts "Success"
puts "obj.foo = " + obj.foo
~/projects/cloby ➔ jruby -rubygems -rjavalib/clojure-1.2.0.jar examples/simple.rb
obj.foo = foo
Setting obj.foo to 'bar'
Oops, need a transaction
Trying again with a transaction
Success
obj.foo = bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment