Class: Consolle::Server::RequestBroker::RequestFuture
- Inherits:
-
Object
- Object
- Consolle::Server::RequestBroker::RequestFuture
- Defined in:
- lib/consolle/server/request_broker.rb
Overview
Simple future implementation
Instance Method Summary collapse
- #get(timeout: nil) ⇒ Object
-
#initialize ⇒ RequestFuture
constructor
A new instance of RequestFuture.
- #set(value) ⇒ Object
Constructor Details
#initialize ⇒ RequestFuture
Returns a new instance of RequestFuture.
237 238 239 240 241 242 |
# File 'lib/consolle/server/request_broker.rb', line 237 def initialize @mutex = Mutex.new @condition = ConditionVariable.new @value = nil @set = false end |
Instance Method Details
#get(timeout: nil) ⇒ Object
252 253 254 255 256 257 258 259 260 |
# File 'lib/consolle/server/request_broker.rb', line 252 def get(timeout: nil) @mutex.synchronize do unless @set @condition.wait(@mutex, timeout) raise Timeout::Error, 'Future timed out' unless @set end @value end end |
#set(value) ⇒ Object
244 245 246 247 248 249 250 |
# File 'lib/consolle/server/request_broker.rb', line 244 def set(value) @mutex.synchronize do @value = value @set = true @condition.signal end end |