Class: ActionCable::Server::StreamEventLoop

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

Instance Method Summary collapse

Constructor Details

#initializeStreamEventLoop

Returns a new instance of StreamEventLoop.



10
11
12
13
14
15
16
17
# File 'lib/action_cable/server/stream_event_loop.rb', line 10

def initialize
  @nio = @thread = nil
  @map = {}
  @stopping = false
  @todo = Queue.new

  @spawn_mutex = Mutex.new
end

Instance Method Details

#attach(io, stream) ⇒ Object



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

def attach(io, stream)
  @todo << lambda do
    @map[io] = @nio.register(io, :r)
    @map[io].value = stream
  end
  wakeup
end

#detach(io, stream) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/action_cable/server/stream_event_loop.rb', line 27

def detach(io, stream)
  @todo << lambda do
    @nio.deregister io
    @map.delete io
    io.close
  end
  wakeup
end

#stopObject



45
46
47
48
# File 'lib/action_cable/server/stream_event_loop.rb', line 45

def stop
  @stopping = true
  wakeup if @nio
end

#writes_pending(io) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/action_cable/server/stream_event_loop.rb', line 36

def writes_pending(io)
  @todo << lambda do
    if monitor = @map[io]
      monitor.interests = :rw
    end
  end
  wakeup
end