sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/

lib/sup/update.rb (858B) - raw

      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 Redwood::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