Sha256: e2f142433745b7fc1fbc664850ff8a4be94851992097bc90022e8c956eb0d220

Contents?: true

Size: 838 Bytes

Versions: 8

Compression:

Stored size: 838 Bytes

Contents

require 'faye/websocket'
require 'eventmachine'

module Slack
  module RealTime
    module Concurrency
      module Eventmachine
        class Socket < Slack::RealTime::Socket
          def start_async
            thread = ensure_reactor_running

            yield self if block_given?

            thread
          end

          def send_data(message)
            driver.send(message)
          end

          protected

          # @return [Thread]
          def ensure_reactor_running
            return if EventMachine.reactor_running?

            reactor = Thread.new { EventMachine.run }
            Thread.pass until EventMachine.reactor_running?
            reactor
          end

          def connect
            @driver = ::Faye::WebSocket::Client.new(url, nil, options)
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
slack-ruby-client-bhe-0.5.5 lib/slack/real_time/concurrency/eventmachine.rb
slack-ruby-client-bhe-0.5.4 lib/slack/real_time/concurrency/eventmachine.rb
slack-ruby-client-0.6.0 lib/slack/real_time/concurrency/eventmachine.rb
slack-ruby-client-0.5.4 lib/slack/real_time/concurrency/eventmachine.rb
slack-ruby-client-0.5.3 lib/slack/real_time/concurrency/eventmachine.rb
slack-ruby-client-0.5.2 lib/slack/real_time/concurrency/eventmachine.rb
slack-ruby-client-0.5.1 lib/slack/real_time/concurrency/eventmachine.rb
slack-ruby-client-0.5.0 lib/slack/real_time/concurrency/eventmachine.rb