Class: Igniter::Store::NetworkBackend::Subscription

Inherits:
Object
  • Object
show all
Includes:
WireProtocol
Defined in:
lib/igniter/store/network_backend.rb

Overview

Handle returned by #subscribe. Call #close to unsubscribe.

Constant Summary

Constants included from WireProtocol

WireProtocol::FRAME_CRC_SIZE, WireProtocol::FRAME_HEADER_SIZE

Instance Method Summary collapse

Methods included from WireProtocol

#encode_frame, #read_frame

Constructor Details

#initialize(socket, thread) ⇒ Subscription

Returns a new instance of Subscription.



37
38
39
40
# File 'lib/igniter/store/network_backend.rb', line 37

def initialize(socket, thread)
  @socket = socket
  @thread = thread
end

Instance Method Details

#closeObject



42
43
44
45
46
47
48
49
50
# File 'lib/igniter/store/network_backend.rb', line 42

def close
  begin
    @socket.write(encode_frame(JSON.generate({ op: "close" })))
  rescue IOError, Errno::EPIPE, Errno::ECONNRESET
    nil
  end
  @socket.close rescue nil
  @thread.kill rescue nil
end