class Google::Gax::Event
Container for a thread adding the ability to cancel, check if set, and get the result of the thread.
Attributes
canceller[RW]
result[R]
Public Class Methods
new()
click to toggle source
# File lib/google/gax/bundling.rb, line 379 def initialize @canceller = nil @result = nil @is_set = false @mutex = Mutex.new @resource = ConditionVariable.new end
Public Instance Methods
cancel()
click to toggle source
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.
# File lib/google/gax/bundling.rb, line 410 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
result=(obj)
click to toggle source
Setter for the result that is synchronized and broadcasts when set.
@param obj [Object] an object. @return [Object] return the passed in param to maintain closure.
# File lib/google/gax/bundling.rb, line 391 def result=(obj) @mutex.synchronize do @result = obj @is_set = true @resource.broadcast @result end end
set?()
click to toggle source
Checks to see if the event has been set. A set Event
signals that there is data in @result. @return [Boolean] Whether the event has been set.
# File lib/google/gax/bundling.rb, line 403 def set? @is_set end
wait(timeout_millis: nil)
click to toggle source
This is used to wait for a bundle request is complete and the event result is set.
@param timeout_millis [Numeric] The number of milliseconds to wait
before ceasing to wait. If nil, this function will wait indefinitely.
# File lib/google/gax/bundling.rb, line 427 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