Sha256: c16dc1862f43587382e0b2a761b6db7fe3039b94cee0f1c93af24b0e932e8181

Contents?: true

Size: 511 Bytes

Versions: 1

Compression:

Stored size: 511 Bytes

Contents

module Restruct
  class Channel < Structure

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

    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

    private

    def serialize(string)
      string
    end

    def deserialize(string)
      string
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
restruct-0.2.0 lib/restruct/channel.rb