Martin Hart wrote:
> On 1/10/03, 5:34:39 PM, Tom Sawyer <transami / transami.net> wrote regarding 
> Re: [slightly OT] Using Observer pattern in client/server architecture - 
> how?:

Have you ruled out drb? It handles procs correctly, so the client can 
send the server a proc to be called later. Example:

======= server.rb ===========

require 'drb'

class Server
   def initialize
     @observers = []
   end

   def register(value, &action)
     @observers << [value, action]
   end

   def x=(new_x)
     @x = new_x
     @observers.each do |value, action|
       if value == new_x
         action[new_x]
       end
     end
   end

   def x
     @x
   end

end

server = Server.new

DRb.start_service('druby://localhost:9500', server)
puts DRb.uri

server.x = 0
loop do
   server.x += 1
   sleep 0.01
   if server.x > 1000
     puts "1000"
     server.x = 0
   end
end

========= client.rb =======

require 'drb'
DRb.start_service()
server = DRbObject.new(nil, 'druby://localhost:9500')

(0..9).each do |i|
   server.register 100*i + i do |val| puts val end
end

sleep

===========================

The server output is:
1000
1000
1000
...


The client output is:
202
303
404
505
606
707
808
909
0
101
202
303
404
505
...