Guest User

Untitled

a guest
Feb 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. # client.rb
  2.  
  3. class Person
  4. include DataMapper::Resource
  5. include EMRPC::Pid
  6.  
  7. after :update, :process_stats
  8. def process_stats
  9. StatServer.send(:process_stats, self, :stats_processed, person.attributes)
  10. end
  11.  
  12. def stats_processed(result)
  13. # StatServer responded
  14. end
  15. end
  16.  
  17. StatServer = EMRPC::ReconnectingPid.new('emrpc://localhost:4567/')
  18.  
  19. ######################################################################
  20.  
  21. # server.rb
  22.  
  23. class StatServer
  24. include EMRPC::Pid
  25. def process_stats(pid, pid_callback, attributes)
  26. # do something ...
  27. # reply to pid:
  28. pid.send(pid_callback, {:answer => 42})
  29. end
  30. end
  31.  
  32. EM::run do
  33. ss = StatServer.new
  34. ss.bind('emrpc://localhost:4567/')
  35. end
Add Comment
Please, Sign In to add comment