Sha256: ac07f697446ad4f3549a7d73c51407b6bfb06a2722c2aed7c00f6d9d38b6403b

Contents?: true

Size: 755 Bytes

Versions: 1

Compression:

Stored size: 755 Bytes

Contents

require 'rlyeh/filters'

module Rlyeh
  class Session
    attr_reader :id, :channel, :connections

    def initialize(id)
      @id = id
      @channel = EventMachine::Channel.new
      @connections = {}
    end

    def attach(connection)
      connection.attached self

      @connections[connection] = @channel.subscribe do |msg|
        connection.send_data msg
      end
    end

    def detach(connection)
      id = @connections.delete connection
      @channel.unsubscribe id if id

      connection.detached self
    end

    def close
    end

    def send_data(data)
      @channel.push data
    end

    def empty?
      @connections.empty?
    end

    include Rlyeh::Filters
    define_filters :attach, :detach, :close, :send_data
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rlyeh-0.0.2 lib/rlyeh/session.rb