]> git.cworth.org Git - sup/blob - lib/sup/update.rb
Merge branch 'buffer-rolling'
[sup] / lib / sup / update.rb
1 module Redwood
2
3 ## Classic listener/broadcaster paradigm. Handles communication between various
4 ## parts of Sup.
5 ##
6 ## Usage note: don't pass threads around. Neither thread nor message equality is
7 ## defined anywhere in Sup beyond standard object equality. To communicate
8 ## something about a particular thread, just pass a representative message from
9 ## it around.
10 ##
11 ## (This assumes that no message will be a part of more than one thread within a
12 ## single "view". Luckily, that's true.)
13
14 class UpdateManager
15   include Singleton
16
17   def initialize
18     @targets = {}
19   end
20
21   def register o; @targets[o] = true; end
22   def unregister o; @targets.delete o; end
23
24   def relay sender, type, *args
25     meth = "handle_#{type}_update".intern
26     @targets.keys.each { |o| o.send meth, sender, *args unless o == sender if o.respond_to? meth }
27   end
28 end
29
30 end