Class: Akasha::Storage::HttpEventStore::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/akasha/storage/http_event_store/stream.rb

Overview

HTTP Eventstore stream.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, stream_name) ⇒ Stream

Returns a new instance of Stream


8
9
10
11
# File 'lib/akasha/storage/http_event_store/stream.rb', line 8

def initialize(client, stream_name)
  @client = client
  @name = stream_name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


6
7
8
# File 'lib/akasha/storage/http_event_store/stream.rb', line 6

def name
  @name
end

Instance Method Details

#metadataObject

Reads stream metadata.


39
40
41
# File 'lib/akasha/storage/http_event_store/stream.rb', line 39

def 
  @client.(@name)
end

#metadata=(metadata) ⇒ Object

Updates stream metadata.


44
45
46
# File 'lib/akasha/storage/http_event_store/stream.rb', line 44

def metadata=()
  @client.(@name, )
end

#read_events(start, page_size, poll = 0) ⇒ Object

Reads events from the stream starting from `start` inclusive. If block given, reads all events from the position in pages of `page_size`. If block not given, reads `size` events from the position. You can also turn on long-polling using `poll` and setting it to the number of seconds to wait for.


24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/akasha/storage/http_event_store/stream.rb', line 24

def read_events(start, page_size, poll = 0)
  if block_given?
    position = start
    loop do
      events = read_events(position, page_size, poll)
      return if events.empty?
      yield(events)
      position += events.size
    end
  else
    @client.retry_read_events_forward(@name, start, page_size, poll)
  end
end

#write_events(events) ⇒ Object

Appends events to the stream.


14
15
16
17
# File 'lib/akasha/storage/http_event_store/stream.rb', line 14

def write_events(events)
  return if events.empty?
  @client.retry_append_to_stream(@name, events)
end