Class: Tamashii::Server::Connection::StreamEventLoop
- Inherits:
-
Object
- Object
- Tamashii::Server::Connection::StreamEventLoop
- Defined in:
- lib/tamashii/server/connection/stream_event_loop.rb
Overview
:nodoc:
Instance Method Summary collapse
- #attach(io, stream) ⇒ Object
- #detach(io, _) ⇒ Object
-
#initialize ⇒ StreamEventLoop
constructor
A new instance of StreamEventLoop.
- #post(task = nil, &block) ⇒ Object
- #stop ⇒ Object
- #stopped? ⇒ Boolean
- #timer(interval, &block) ⇒ Object
- #writes_pending(io) ⇒ Object
Constructor Details
#initialize ⇒ StreamEventLoop
Returns a new instance of StreamEventLoop.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/tamashii/server/connection/stream_event_loop.rb', line 10 def initialize @nio = @thread = nil @stopping = false @streams = {} @todo = Queue.new @spawn_mutex = Mutex.new end |
Instance Method Details
#attach(io, stream) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/tamashii/server/connection/stream_event_loop.rb', line 32 def attach(io, stream) @todo << lambda do @streams[io] = @nio.register(io, :r) @streams[io].value = stream end wakeup end |
#detach(io, _) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/tamashii/server/connection/stream_event_loop.rb', line 40 def detach(io, _) @todo << lambda do @nio.deregister io @streams.delete io io.close end wakeup end |
#post(task = nil, &block) ⇒ Object
27 28 29 30 |
# File 'lib/tamashii/server/connection/stream_event_loop.rb', line 27 def post(task = nil, &block) task ||= block Concurrent.global_io_executor << task end |
#stop ⇒ Object
57 58 59 60 |
# File 'lib/tamashii/server/connection/stream_event_loop.rb', line 57 def stop @stopping = true wakeup if @nio end |
#stopped? ⇒ Boolean
62 63 64 |
# File 'lib/tamashii/server/connection/stream_event_loop.rb', line 62 def stopped? @stopping end |
#timer(interval, &block) ⇒ Object
21 22 23 24 25 |
# File 'lib/tamashii/server/connection/stream_event_loop.rb', line 21 def timer(interval, &block) Concurrent::TimerTask.new( execution_interval: interval, &block ).tap(&:execute) end |
#writes_pending(io) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/tamashii/server/connection/stream_event_loop.rb', line 49 def writes_pending(io) @todo << lambda do monitor = @streams[io] monitor&.interests = :rw end wakeup end |