Sha256: 3bff9e12db1ca7e2e39e27ce6ba67e794e052e967923a38e836d6bf87f66c425

Contents?: true

Size: 839 Bytes

Versions: 26

Compression:

Stored size: 839 Bytes

Contents

module Euston
  module EventStore
    module Dispatcher
      class AsynchronousDispatcher
        def initialize(bus, persistence, &block)
          @bus = bus
          @persistence = persistence
          @handle_exception = block_given? ? block : Proc.new {}

          start
        end

        def dispatch(commit)
          Thread.fork(commit) { |c| begin_dispatch c }
        end

        protected

        def begin_dispatch(commit)
          begin
            @bus.publish commit
            @persistence.mark_commit_as_dispatched commit
          rescue Exception => e
            @handle_exception.call commit, e
          end
        end

        private

        def start
          @persistence.init
          @persistence.get_undispatched_commits.each { |commit| dispatch commit }
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
euston-eventstore-1.2.7 lib/euston-eventstore/dispatcher/asynchronous_dispatcher.rb
euston-eventstore-1.2.7-java lib/euston-eventstore/dispatcher/asynchronous_dispatcher.rb
euston-eventstore-1.2.6 lib/euston-eventstore/dispatcher/asynchronous_dispatcher.rb
euston-eventstore-1.2.6-java lib/euston-eventstore/dispatcher/asynchronous_dispatcher.rb
euston-eventstore-1.2.5-java lib/euston-eventstore/dispatcher/asynchronous_dispatcher.rb
euston-eventstore-1.2.5 lib/euston-eventstore/dispatcher/asynchronous_dispatcher.rb
euston-eventstore-1.2.4 lib/euston-eventstore/dispatcher/asynchronous_dispatcher.rb
euston-eventstore-1.2.4-java lib/euston-eventstore/dispatcher/asynchronous_dispatcher.rb
euston-eventstore-1.2.3 lib/euston-eventstore/dispatcher/asynchronous_dispatcher.rb
euston-eventstore-1.2.3-java lib/euston-eventstore/dispatcher/asynchronous_dispatcher.rb
euston-eventstore-1.2.2 lib/euston-eventstore/dispatcher/asynchronous_dispatcher.rb
euston-eventstore-1.2.2-java lib/euston-eventstore/dispatcher/asynchronous_dispatcher.rb
euston-eventstore-1.2.1-java lib/euston-eventstore/dispatcher/asynchronous_dispatcher.rb
euston-eventstore-1.2.1 lib/euston-eventstore/dispatcher/asynchronous_dispatcher.rb
euston-eventstore-1.2.0 lib/euston-eventstore/dispatcher/asynchronous_dispatcher.rb
euston-eventstore-1.2.0-java lib/euston-eventstore/dispatcher/asynchronous_dispatcher.rb
euston-eventstore-1.1.0 lib/euston-eventstore/dispatcher/asynchronous_dispatcher.rb
euston-eventstore-1.1.0-java lib/euston-eventstore/dispatcher/asynchronous_dispatcher.rb
euston-eventstore-1.0.4-java lib/euston-eventstore/dispatcher/asynchronous_dispatcher.rb
euston-eventstore-1.0.4 lib/euston-eventstore/dispatcher/asynchronous_dispatcher.rb