Class: Pollen::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/pollen/server.rb

Instance Method Summary collapse

Constructor Details

#initializeExecutor

Returns a new instance of Executor.



5
6
7
8
9
10
# File 'lib/pollen/server.rb', line 5

def initialize
  @events = {}
  @incoming = []
  @mutex = Mutex.new
  @event_loop = EventLoop.new
end

Instance Method Details

#accept(connection) ⇒ Object



26
27
28
29
30
31
# File 'lib/pollen/server.rb', line 26

def accept(connection)
  Rails.logger.info "Creating connection for stream #{connection.stream_id}"
  @mutex.synchronize do
    @incoming << connection
  end
end

#push(stream_id, event, data) ⇒ Object



19
20
21
22
23
24
# File 'lib/pollen/server.rb', line 19

def push(stream_id, event, data)
  Rails.logger.info "Pushing data for stream #{stream_id}, event: #{event}"
  @mutex.synchronize do
    @events[stream_id] = { event:, data: }
  end
end

#start!Object



12
13
14
15
16
17
# File 'lib/pollen/server.rb', line 12

def start!
  @thread = Thread.new do
    start_loop
  end
  self
end