Class: Estore::Session
- Inherits:
-
Object
- Object
- Estore::Session
- Extended by:
- Forwardable
- Defined in:
- lib/estore/session.rb
Overview
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.
Instance Method Summary collapse
- #append(stream, events, options = {}) ⇒ Object
- #close ⇒ Object
-
#initialize(host, port = 2113) ⇒ Session
constructor
A new instance of Session.
- #ping ⇒ Object
- #read(stream, options = {}) ⇒ Object
- #read_batch(stream, from, limit) ⇒ Object
- #read_forward(stream, from, batch_size = nil, &block) ⇒ Object
- #subscription(stream, options = {}) ⇒ Object
Constructor Details
#initialize(host, port = 2113) ⇒ Session
Returns a new instance of Session.
20 21 22 |
# File 'lib/estore/session.rb', line 20 def initialize(host, port = 2113) @connection = Connection.new(host, port) end |
Instance Method Details
#append(stream, events, options = {}) ⇒ Object
51 52 53 |
# File 'lib/estore/session.rb', line 51 def append(stream, events, = {}) command(Commands::Append, stream, events, ).call end |
#close ⇒ Object
24 25 26 |
# File 'lib/estore/session.rb', line 24 def close @connection.close end |
#ping ⇒ Object
28 29 30 |
# File 'lib/estore/session.rb', line 28 def ping command(Commands::Ping) end |
#read(stream, options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/estore/session.rb', line 32 def read(stream, = {}) from = [:from] || 0 limit = [:limit] if limit read_batch(stream, from, limit) else read_forward(stream, from) end end |
#read_batch(stream, from, limit) ⇒ Object
43 44 45 |
# 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) ⇒ Object
47 48 49 |
# 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 = {}) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/estore/session.rb', line 55 def subscription(stream, = {}) if [:from] command(Commands::CatchUpSubscription, stream, [:from], ) else command(Commands::Subscription, stream, ) end end |