Class: ZooKeeper::RubyIO::AsyncOp

Inherits:
AsyncOp
  • Object
show all
Defined in:
lib/zkruby/rubyio.rb

Overview

Binding

Instance Attribute Summary

Attributes inherited from AsyncOp

#backtrace

Instance Method Summary collapse

Methods inherited from AsyncOp

#errback, #errback=, #value

Constructor Details

#initialize(binding, &callback) ⇒ AsyncOp

Returns a new instance of AsyncOp.



253
254
255
256
257
258
# File 'lib/zkruby/rubyio.rb', line 253

def initialize(binding,&callback)
    @mutex = Monitor.new
    @cv = @mutex.new_cond()
    @callback = callback
    @rubyio = binding
end

Instance Method Details

#resume(error, response) ⇒ Object



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/zkruby/rubyio.rb', line 260

def resume(error,response)
    mutex.synchronize do
        @error = error
        @result = nil
        begin
            @result = @callback.call(response) unless error
        rescue StandardError => ex
            @error = ex
        end
       
        if @error && @errback
            begin
                @result = @errback.call(@error) 
                @error = nil
            rescue StandardError => ex
                @error = ex
            end
        end

        cv.signal()
    end
end