Last active
August 29, 2015 14:04
-
-
Save havenwood/c67d47cb131976107080 to your computer and use it in GitHub Desktop.
Playing around with Rinda TupleSpace
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
require_relative 'tuplespace' | |
DRb.start_service | |
space = TupleSpace.new tuple_space: DRbObject.new(nil, 'druby://0.0.0.0:3000') |
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
require_relative 'tuplespace' | |
space = TupleSpace.new | |
DRb.start_service 'druby://0.0.0.0:3000', space.tuple_space |
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
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