Class: Google::Gax::Event
- Inherits:
-
Object
- Object
- Google::Gax::Event
- Defined in:
- lib/google/gax/bundling.rb
Overview
Container for a thread adding the ability to cancel, check if set, and get the result of the thread.
Instance Attribute Summary collapse
-
#canceller ⇒ Object
Returns the value of attribute canceller.
-
#result ⇒ Object
Returns the value of attribute result.
Instance Method Summary collapse
-
#cancel ⇒ Object
Invokes the cancellation function provided.
-
#initialize ⇒ Event
constructor
A new instance of Event.
-
#set? ⇒ Boolean
Checks to see if the event has been set.
-
#wait(timeout_millis: nil) ⇒ Object
This is used to wait for a bundle request is complete and the event result is set.
Constructor Details
#initialize ⇒ Event
Returns a new instance of Event.
376 377 378 379 380 381 382 |
# File 'lib/google/gax/bundling.rb', line 376 def initialize @canceller = nil @result = nil @is_set = false @mutex = Mutex.new @resource = ConditionVariable.new end |
Instance Attribute Details
#canceller ⇒ Object
Returns the value of attribute canceller.
373 374 375 |
# File 'lib/google/gax/bundling.rb', line 373 def canceller @canceller end |
#result ⇒ Object
Returns the value of attribute result.
374 375 376 |
# File 'lib/google/gax/bundling.rb', line 374 def result @result end |
Instance Method Details
#cancel ⇒ Object
Invokes the cancellation function provided. The returned cancellation function returns true if all elements was removed successfully from the inputs, and false if it was not.
407 408 409 410 411 412 413 414 415 416 |
# File 'lib/google/gax/bundling.rb', line 407 def cancel @mutex.synchronize do cancelled = canceller.nil? ? false : canceller.call # Broadcast if the event was successfully cancelled. If not, # the result should end up getting set by the sent api request. # When the result is set, the resource is going to broadcast. @resource.broadcast if cancelled cancelled end end |
#set? ⇒ Boolean
Checks to see if the event has been set. A set Event signals that there is data in @result.
400 401 402 |
# File 'lib/google/gax/bundling.rb', line 400 def set? @is_set end |
#wait(timeout_millis: nil) ⇒ Object
This is used to wait for a bundle request is complete and the event result is set.
424 425 426 427 428 429 430 431 |
# File 'lib/google/gax/bundling.rb', line 424 def wait(timeout_millis: nil) @mutex.synchronize do return @is_set if @is_set t = timeout_millis.nil? ? nil : timeout_millis / MILLIS_PER_SECOND @resource.wait(@mutex, t) @is_set end end |