]> git.cworth.org Git - sup/blob - lib/sup/update.rb
updated imap internaldate notes in comments
[sup] / lib / sup / update.rb
1 module Redwood
2
3 ## Classic listener/sender paradigm. Handles communication between various
4 ## parts of Sup.
5 ##
6 ## Usage note: don't pass threads around. Neither thread nor message equality
7 ## is defined beyond standard object equality. For Thread equality, this is
8 ## because of computational cost. But message equality is trivial by comparing
9 ## message ids, so to communicate something about a particular thread, just
10 ## pass a representative message from it instead.
11 ##
12 ## This assumes that no message will be a part of more than one thread within
13 ## a single "view" (otherwise a message from a thread wouldn't uniquely
14 ## identify it). But that's true.
15
16 class UpdateManager
17   include Singleton
18
19   def initialize
20     @targets = {}
21     self.class.i_am_the_instance self
22   end
23
24   def register o; @targets[o] = true; end
25   def unregister o; @targets.delete o; end
26
27   def relay sender, type, *args
28     meth = "handle_#{type}_update".intern
29     @targets.keys.each { |o| o.send meth, sender, *args unless o == sender if o.respond_to? meth }
30   end
31 end
32
33 end