Skip to content

Instantly share code, notes, and snippets.

@headius
Created December 9, 2010 02:26
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save headius/734247 to your computer and use it in GitHub Desktop.
Save headius/734247 to your computer and use it in GitHub Desktop.
~/projects ➔ gem install cloby
Successfully installed cloby-0.0.1-java
1 gem installed
Installing ri documentation for cloby-0.0.1-java...
Installing RDoc documentation for cloby-0.0.1-java...
~/projects ➔ cat 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 ➔ jruby -rubygems -rclojure/clojure-1.0.0.jar 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