Sha256: 96f5fec6486a72e3e6f1c2fb11069d9fd46ecb03e8702cbc95afb279a83f9a9a

Contents?: true

Size: 772 Bytes

Versions: 2

Compression:

Stored size: 772 Bytes

Contents

module InboxSync
  class Sync; end

  class Sync::MailItemGroup

    attr_reader :thread, :items

    def initialize(sync)
      @sync = sync
      @thread = nil
      @items = []
    end

    def id
      "#<#{self.class}:#{'0x%x' % (self.object_id << 1)}>"
    end

    def add(mail_item)
      @items << mail_item
    end

    def run(runner=nil)
      @runner = runner
      @thread = Thread.new { run_items_thread }
    end

    def join
      @thread.join
      @runner = nil
    end

    protected

    def run_items_thread
      @items.each do |item|
        if @runner && @runner.shutdown?
          @sync.logger.debug "* the runner has been shutdown - aborting #{id} sync thread"
          break
        end
        @sync.run(item)
      end
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
inbox-sync-0.4.1 lib/inbox-sync/sync/mail_item_group.rb
inbox-sync-0.4.0 lib/inbox-sync/sync/mail_item_group.rb