Sha256: d627724f9af1015ab715437214fc65f924f791f8d58494b8e8abda18a0e7ad9e

Contents?: true

Size: 822 Bytes

Versions: 12

Compression:

Stored size: 822 Bytes

Contents

module EventSourcery
  module EventStore

    # This class provides a basic poll waiter implementation that calls the provided block and sleeps for the specified interval, to be used by a {Subscription}.
    class PollWaiter
      #
      # @param interval [Float] Optional. Will default to `0.5`
      def initialize(interval: 0.5)
        @interval = interval
      end

      # Start polling. Call the provided block and sleep. Repeat until `:stop` is thrown (usually via a subscription master).
      #
      # @param block [Proc] code block to be called when polling
      #
      # @see SignalHandlingSubscriptionMaster
      # @see Subscription
      def poll(&block)
        catch(:stop) do
          loop do
            block.call
            sleep @interval
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
event_sourcery-1.0.0 lib/event_sourcery/event_store/poll_waiter.rb
event_sourcery-0.24.0 lib/event_sourcery/event_store/poll_waiter.rb
event_sourcery-0.23.1 lib/event_sourcery/event_store/poll_waiter.rb
event_sourcery-0.23.0 lib/event_sourcery/event_store/poll_waiter.rb
event_sourcery-0.22.0 lib/event_sourcery/event_store/poll_waiter.rb
event_sourcery-0.21.0 lib/event_sourcery/event_store/poll_waiter.rb
event_sourcery-0.20.0 lib/event_sourcery/event_store/poll_waiter.rb
event_sourcery-0.19.0 lib/event_sourcery/event_store/poll_waiter.rb
event_sourcery-0.18.0 lib/event_sourcery/event_store/poll_waiter.rb
event_sourcery-0.17.0 lib/event_sourcery/event_store/poll_waiter.rb
event_sourcery-0.16.1 lib/event_sourcery/event_store/poll_waiter.rb
event_sourcery-0.15.0 lib/event_sourcery/event_store/poll_waiter.rb