Class: ZooKeeper::AsyncOp

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

Overview

Returned by asynchronous calls

Examples:

op = zk.stat("\apath") { |stat| something_with_stat() }

op.on_error do |err|
  case err
  when ZK::Error::SESSION_EXPIRED 
       puts "Ignoring session expired"
  else
       raise err
  end
end

begin
   result_of_somthing_with_stat = op.value
rescue StandardError => ex
   puts "Oops, my error handler raised an exception"
end

Direct Known Subclasses

EventMachine::AsyncOp, RubyIO::AsyncOp, WrappedOp

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#backtraceObject

Returns the value of attribute backtrace.



142
143
144
# File 'lib/zkruby/protocol.rb', line 142

def backtrace
  @backtrace
end

Instance Method Details

#errback(&block) {|the| ... } ⇒ Object Also known as: on_error

Provide an error callback.

Parameters:

  • block

    the error callback as a block

Yield Parameters:

  • the (StandardError)

    error raised by the zookeeper operation OR by its callback



147
148
149
# File 'lib/zkruby/protocol.rb', line 147

def errback(&block)
    set_error_handler(block)
end

#errback=(block) ⇒ Object

Parameters:

  • block

    the error callback as a Proc



152
153
154
# File 'lib/zkruby/protocol.rb', line 152

def errback=(block)
    set_error_handler(block)
end

#valueObject

Wait for the async op to finish and returns its value will raise an exception if

the operation itself fails and there is no error handler
the callback raises a StandardError and there is no error handler
the error handler raises StandardError


163
164
165
166
167
168
169
# File 'lib/zkruby/protocol.rb', line 163

def value();
    wait_value()
    rescue ZooKeeper::Error => ex
       # Set the backtrace to the original caller, rather than the ZK event loop
       ex.set_backtrace(@backtrace) if @backtrace
       raise ex
end