lib/em-midori/eventsource.rb in em-midori-0.0.9.2 vs lib/em-midori/eventsource.rb in em-midori-0.0.9.3
- old
+ new
@@ -1,11 +1,17 @@
+##
+# 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