Sha256: f228957ef9511500ece98d2b721e6fe3aa72163e359414dbe5d458e26eec03b4

Contents?: true

Size: 917 Bytes

Versions: 14

Compression:

Stored size: 917 Bytes

Contents

module MailRoom
  # Coordinate the mailbox watchers
  # @author Tony Pitale
  class Coordinator
    attr_accessor :watchers, :running

    # build watchers for a set of mailboxes
    # @params mailboxes [Array<MailRoom::Mailbox>] mailboxes to be watched
    def initialize(mailboxes)
      self.watchers = []

      mailboxes.each {|box| self.watchers << MailboxWatcher.new(box)}
    end

    alias :running? :running

    # start each of the watchers to running
    def run
      watchers.each(&:run)
      
      self.running = true
      
      sleep_while_running
    ensure
      quit
    end

    # quit each of the watchers when we're done running
    def quit
      watchers.each(&:quit)
    end

    private
    # @private
    def sleep_while_running
      # do we need to sweep for dead watchers?
      # or do we let the mailbox rebuild connections
      while(running?) do; sleep 1; end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
mail_room-0.11.1 lib/mail_room/coordinator.rb
mail_room-0.11.0 lib/mail_room/coordinator.rb
mail_room-0.10.1 lib/mail_room/coordinator.rb
gitlab-mail_room-0.0.8 lib/mail_room/coordinator.rb
gitlab-mail_room-0.0.7 lib/mail_room/coordinator.rb
gitlab-mail_room-0.0.6 lib/mail_room/coordinator.rb
gitlab-mail_room-0.0.4 lib/mail_room/coordinator.rb
gitlab-mail_room-0.0.3 lib/mail_room/coordinator.rb
gitlab-mail_room-0.0.2 lib/mail_room/coordinator.rb
mail_room-0.10.0 lib/mail_room/coordinator.rb
mail_room-0.9.1 lib/mail_room/coordinator.rb
mail_room-0.9.0 lib/mail_room/coordinator.rb
mail_room-0.8.1 lib/mail_room/coordinator.rb
mail_room-0.8.0 lib/mail_room/coordinator.rb