Sha256: fee5541224df86869249ff2218ef71501bdd5b4d0a5c14c592f46e4857556240

Contents?: true

Size: 688 Bytes

Versions: 1

Compression:

Stored size: 688 Bytes

Contents

require 'rlyeh/filter'

module Rlyeh
  class Session
    include Rlyeh::Filter

    attr_accessor :channel, :connections

    def initialize
      @channel = EventMachine::Channel.new
      @subscribers = {}
    end

    def attach(conn)
      conn.attached self

      @subscribers[conn] = @channel.subscribe do |msg|
        conn.send_data msg
      end
    end

    def detach(conn)
      id = @subscribers.delete conn
      @channel.unsubscribe id if id

      conn.detached self
    end

    def close
    end

    def send_data(data)
      @channel.push data
    end

    def empty?
      @subscribes.empty?
    end

    define_filter :attach, :detach, :close, :send_data
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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