Skip to content

Instantly share code, notes, and snippets.

@havenwood
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/c67d47cb131976107080 to your computer and use it in GitHub Desktop.
Save havenwood/c67d47cb131976107080 to your computer and use it in GitHub Desktop.
Playing around with Rinda TupleSpace
require_relative 'tuplespace'
DRb.start_service
space = TupleSpace.new tuple_space: DRbObject.new(nil, 'druby://0.0.0.0:3000')
require_relative 'tuplespace'
space = TupleSpace.new
DRb.start_service 'druby://0.0.0.0:3000', space.tuple_space
require 'rinda/tuplespace'
class TupleSpace
attr_reader :tuple_space
def initialize period: 60, timeout: 0.00001, tuple_space: nil
@timeout = timeout
@tuple_space = tuple_space || Rinda::TupleSpace.new(period)
end
def []= k, v
@tuple_space.write [k, v]
end
def [] k
@tuple_space.read([k, nil], @timeout).last
end
def delete k
@tuple_space.take([k, nil], @timeout).last
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment