class Estore::Session

The Session class is responsible for maintaining a full-duplex connection between the client and the Event Store server. An Estore session is thread-safe, and it is recommended to only have one instance per application.

All operations are handled fully asynchronously, returning a promise. If you need to execute synchronously, simply call .sync on the returned promise.

To get maximum performance from the connection, it is recommended to use it asynchronously.

Public Class Methods

new(host, port = 2113) click to toggle source
# File lib/estore/session.rb, line 20
def initialize(host, port = 2113)
  @connection = Connection.new(host, port)
end

Public Instance Methods

append(stream, events, options = {}) click to toggle source
# File lib/estore/session.rb, line 51
def append(stream, events, options = {})
  command(Commands::Append, stream, events, options).call
end
close() click to toggle source
# File lib/estore/session.rb, line 24
def close
  @connection.close
end
ping() click to toggle source
# File lib/estore/session.rb, line 28
def ping
  command(Commands::Ping).call
end
read(stream, options = {}) click to toggle source
# File lib/estore/session.rb, line 32
def read(stream, options = {})
  from = options[:from] || 0
  limit = options[:limit]

  if limit
    read_batch(stream, from, limit)
  else
    read_forward(stream, from)
  end
end
read_batch(stream, from, limit) click to toggle source
# File lib/estore/session.rb, line 43
def read_batch(stream, from, limit)
  command(Commands::ReadBatch, stream, from, limit).call
end
read_forward(stream, from, batch_size = nil, &block) click to toggle source
# File lib/estore/session.rb, line 47
def read_forward(stream, from, batch_size = nil, &block)
  command(Commands::ReadForward, stream, from, batch_size, &block).call
end
subscription(stream, options = {}) click to toggle source
# File lib/estore/session.rb, line 55
def subscription(stream, options = {})
  if options[:from]
    command(Commands::CatchUpSubscription, stream, options[:from], options)
  else
    command(Commands::LiveSubscription, stream, options)
  end
end

Private Instance Methods

command(command, *args) click to toggle source
# File lib/estore/session.rb, line 65
def command(command, *args)
  command.new(@connection, *args)
end