Class: IOPromise::Dalli::DalliPromise
- Inherits:
-
Base
- Object
- Base
- IOPromise::Dalli::DalliPromise
- Defined in:
- lib/iopromise/dalli/promise.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #execute_pool ⇒ Object
- #in_select_loop ⇒ Object
-
#initialize(server = nil, key = nil) ⇒ DalliPromise
constructor
A new instance of DalliPromise.
- #timeout? ⇒ Boolean
- #timeout_remaining ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize(server = nil, key = nil) ⇒ DalliPromise
Returns a new instance of DalliPromise.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/iopromise/dalli/promise.rb', line 10 def initialize(server = nil, key = nil) super() # when created from a 'then' call, initialize nothing return if server.nil? || key.nil? @server = server @key = key @start_time = nil ::IOPromise::ExecutorContext.current.register(self) end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
8 9 10 |
# File 'lib/iopromise/dalli/promise.rb', line 8 def key @key end |
Instance Method Details
#execute_pool ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/iopromise/dalli/promise.rb', line 31 def execute_pool return @pool if defined?(@pool) if defined?(@server) @pool = DalliExecutorPool.for(@server) else @pool = nil end end |
#in_select_loop ⇒ Object
40 41 42 43 44 |
# File 'lib/iopromise/dalli/promise.rb', line 40 def in_select_loop if @start_time.nil? @start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) end end |
#timeout? ⇒ Boolean
54 55 56 57 |
# File 'lib/iopromise/dalli/promise.rb', line 54 def timeout? return false if @start_time.nil? timeout_remaining <= 0 end |
#timeout_remaining ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/iopromise/dalli/promise.rb', line 46 def timeout_remaining now = Process.clock_gettime(Process::CLOCK_MONOTONIC) elapsed = now - @start_time remaining = @server.[:socket_timeout] - elapsed return 0 if remaining < 0 remaining end |
#wait ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/iopromise/dalli/promise.rb', line 23 def wait unless defined?(@server) super else ::IOPromise::ExecutorContext.current.wait_for_all_data(end_when_complete: self) end end |