Sha256: 64f6c2f631a305fcc2934d41e5a177c7843459d3c9bd300ba4eeb5b7f8ed61df

Contents?: true

Size: 654 Bytes

Versions: 7

Compression:

Stored size: 654 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

  # @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::Error::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

7 entries across 7 versions & 1 rubygems

Version Path
em-midori-0.1.3 lib/em-midori/eventsource.rb
em-midori-0.1.2 lib/em-midori/eventsource.rb
em-midori-0.1.1 lib/em-midori/eventsource.rb
em-midori-0.1.0 lib/em-midori/eventsource.rb
em-midori-0.0.9.5 lib/em-midori/eventsource.rb
em-midori-0.0.9.4 lib/em-midori/eventsource.rb
em-midori-0.0.9.3 lib/em-midori/eventsource.rb