Class: Restruct::Channel

Inherits:
Structure show all
Defined in:
lib/restruct/channel.rb

Direct Known Subclasses

MarshalChannel

Instance Attribute Summary

Attributes inherited from Structure

#connection, #id

Instance Method Summary collapse

Methods inherited from Structure

#==, #destroy, #dump, #exists?, #initialize, #restore

Constructor Details

This class inherits a constructor from Restruct::Structure

Instance Method Details

#publish(message) ⇒ Object



4
5
6
# File 'lib/restruct/channel.rb', line 4

def publish(message)
  connection.call 'PUBLISH', id, serialize(message)
end

#subscribeObject



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/restruct/channel.rb', line 8

def subscribe
  subscriber = connection.clone
  subscriber.call 'SUBSCRIBE', id
  loop do
    yield deserialize(subscriber.read.last)
  end
rescue => ex
  raise ex
ensure
  subscriber.call 'UNSUBSCRIBE', id
end