class Fluent::Counter::Future

Public Class Methods

new(loop, mutex) click to toggle source
# File lib/fluent/counter/client.rb, line 247
def initialize(loop, mutex)
  @set = false
  @result = nil
  @mutex = mutex
  @loop = loop
end

Public Instance Methods

data() click to toggle source
# File lib/fluent/counter/client.rb, line 268
def data
  get.data
end
errors() click to toggle source
# File lib/fluent/counter/client.rb, line 259
def errors
  get.errors
end
errors?() click to toggle source
# File lib/fluent/counter/client.rb, line 263
def errors?
  es = errors
  es && !es.empty?
end
get() click to toggle source
# File lib/fluent/counter/client.rb, line 272
def get
  # Block until `set` method is called and @result is set
  join if @result.nil?
  @result
end
set(v) click to toggle source
# File lib/fluent/counter/client.rb, line 254
def set(v)
  @result = Result.new(v)
  @set = true
end
wait() click to toggle source
# File lib/fluent/counter/client.rb, line 278
def wait
  res = get
  if res.error?
    Fluent::Counter.raise_error(res.errors.first)
  end
  res
end

Private Instance Methods

join() click to toggle source
# File lib/fluent/counter/client.rb, line 288
def join
  until @set
    @mutex.synchronize do
      @loop.run_once(0.0001) # return a lock as soon as possible
    end
  end
end