Sha256: f688f090927f2c17fb2347138a73b4fa112fe66dc67a771bb917896488b21e19

Contents?: true

Size: 709 Bytes

Versions: 19

Compression:

Stored size: 709 Bytes

Contents

##
# This class provides methods for EventSource connection instance.
# @attr [EM::Connection] connection the connection instance of EventMachine
class Midori::EventSource
  attr_accessor :connection

  # Init a EventSource instance with a connection
  # @param [EM::Connection] connection the connection instance of EventMachine
  def initialize(connection)
    @connection = connection
  end

  # Send data and close the connection
  # @param [String] data data to be sent
  def send(data)
    raise Midori::Exception::EventSourceTypeError unless data.is_a? String
    @connection.send_data(data.split("\n").map {|str| "data: #{str}\n"}.join + "\n")
    @connection.close_connection_after_writing
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
em-midori-0.4.3 lib/midori/eventsource.rb
em-midori-0.4.2.1 lib/midori/eventsource.rb
em-midori-0.4.2 lib/midori/eventsource.rb
em-midori-0.4.1.1 lib/midori/eventsource.rb
em-midori-0.4.1 lib/midori/eventsource.rb
em-midori-0.4.0 lib/midori/eventsource.rb
em-midori-0.3.0 lib/midori/eventsource.rb
em-midori-0.2.4 lib/midori/eventsource.rb
em-midori-0.2.3 lib/midori/eventsource.rb
em-midori-0.2.2 lib/midori/eventsource.rb
em-midori-0.2.1 lib/midori/eventsource.rb
em-midori-0.2.0 lib/midori/eventsource.rb
em-midori-0.1.12 lib/midori/eventsource.rb
em-midori-0.1.11 lib/midori/eventsource.rb
em-midori-0.1.10 lib/midori/eventsource.rb
em-midori-0.1.9 lib/midori/eventsource.rb
em-midori-0.1.8 lib/midori/eventsource.rb
em-midori-0.1.7.1 lib/midori/eventsource.rb
em-midori-0.1.7 lib/midori/eventsource.rb