Class: EventSourcery::EventStore::PollWaiter

Inherits:
Object
  • Object
show all
Defined in:
lib/event_sourcery/event_store/poll_waiter.rb

Overview

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.

Instance Method Summary collapse

Constructor Details

#initialize(interval: 0.5) ⇒ PollWaiter

Returns a new instance of PollWaiter.

Parameters:

  • interval (Float) (defaults to: 0.5)

    Optional. Will default to ‘0.5`



8
9
10
# File 'lib/event_sourcery/event_store/poll_waiter.rb', line 8

def initialize(interval: 0.5)
  @interval = interval
end

Instance Method Details

#poll(&block) ⇒ Object

Start polling. Call the provided block and sleep. Repeat until ‘:stop` is thrown (usually via a subscription master).

Parameters:

  • block (Proc)

    code block to be called when polling

See Also:



18
19
20
21
22
23
24
25
# File 'lib/event_sourcery/event_store/poll_waiter.rb', line 18

def poll(&block)
  catch(:stop) do
    loop do
      block.call
      sleep @interval
    end
  end
end