lib/httpx/selector.rb in httpx-0.1.0 vs lib/httpx/selector.rb in httpx-0.2.0
- old
+ new
@@ -1,8 +1,14 @@
# frozen_string_literal: true
class HTTPX::Selector
+ READABLE = %i[rw r].freeze
+ WRITABLE = %i[rw w].freeze
+
+ private_constant :READABLE
+ private_constant :WRITABLE
+
#
# I/O monitor
#
class Monitor
attr_accessor :value, :interests, :readiness
@@ -13,15 +19,15 @@
@reactor = reactor
@closed = false
end
def readable?
- @interests == :rw || @interests == :r
+ READABLE.include?(@interests)
end
def writable?
- @interests == :rw || @interests == :w
+ WRITABLE.include?(@interests)
end
# closes +@io+, deregisters from reactor (unless +deregister+ is false)
def close(deregister = true)
return if @closed
@@ -58,11 +64,11 @@
end
end
# register +io+ for +interests+ events.
def register(io, interests)
- readable = interests == :r || interests == :rw
- writable = interests == :w || interests == :rw
+ readable = READABLE.include?(interests)
+ writable = WRITABLE.include?(interests)
@lock.synchronize do
if readable
monitor = @readers[io]
if monitor
monitor.interests = interests