Sha256: f5f353a26f01289ac505cf36fb26f8ed14ba407f974a7fabe00a56e010a3c07b

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

module Tribe
  module EM
    class Connection < ::EM::Connection
      include Tribe::Actable

      def initialize(options = {})
        init_actable(options)
      end

      def post_init
        enqueue(:post_init, nil)
      end

      def receive_data(data)
        enqueue(:receive_data, data)
      end

      def unbind
        enqueue(:unbind, nil)
      end

      def process_event(event)
        case event.command
        when :post_init
          post_init_handler(event)
        when :receive_data
          receive_data_handler(event)
        when :unbind
          unbind_handler(event)
        end
      end

      def post_init_handler(event)
        puts "Actor (#{identifier}) connected to client using thread (#{Thread.current.object_id})."
      end

      def receive_data_handler(event)
        puts "Actor (#{identifier}) received data (#{event.data}) using thread (#{Thread.current.object_id})."
      end

      def unbind_handler(event)
        puts "Actor (#{identifier}) disconnected from client using thread (#{Thread.current.object_id})."
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tribe_em-0.0.1 lib/tribe_em/connection.rb