Skip to content

Instantly share code, notes, and snippets.

@seki
Created November 24, 2009 20:53
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 seki/242201 to your computer and use it in GitHub Desktop.
Save seki/242201 to your computer and use it in GitHub Desktop.
#tweet
$ irb
irb(main):001:0> require 'drb/drb'
=> true
irb(main):002:0> DRb.start_service
=> #<DRb::DRbServer:...>
irb(main):003:0> ro = DRbObject.new_with_uri('druby://localhost:54321')
=> #<DRb::DRbObject:0...>
irb(main):004:0> ro.notify('tweet')
=> 1
irb(main):005:0> ro.notify('Hello, World')
=> 2
require 'rinda/tuplespace'
require 'drb/drb'
class Notifier
def initialize
@ts = Rinda::TupleSpace.new
@ts.write([:tail, 0])
end
def notify(it)
tuple = @ts.take([:tail, nil])
tail = tuple[1] + 1
@ts.write([tail, it])
@ts.write([:tail, tail])
tail
end
def receive(key)
@ts.read([key, nil])
end
end
DRb.start_service('druby://localhost:54321', Notifier.new)
while true
sleep 1
end
require 'drb/drb'
DRb.start_service
ro = DRbObject.new_with_uri('druby://localhost:54321')
key = 0
while true
key, obj = ro.receive(key + 1)
p [key, obj]
sleep(3)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment