Class: Midori::EventSource

Inherits:
Object
  • Object
show all
Defined in:
lib/em-midori/eventsource.rb

Overview

This class provides methods for EventSource connection instance.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ EventSource


8
9
10
# File 'lib/em-midori/eventsource.rb', line 8

def initialize(connection)
  @connection = connection
end

Instance Attribute Details

#connectionEM::Connection

the connection instance of EventMachine


4
5
6
# File 'lib/em-midori/eventsource.rb', line 4

def connection
  @connection
end

Instance Method Details

#send(data) ⇒ Object

Send data and close the connection


14
15
16
17
18
# File 'lib/em-midori/eventsource.rb', line 14

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