module Fraggle
  class Client

    %w{rev set get del stat}.each do |cmd|
      class_eval <<-CODE
        alias :a#{cmd} :#{cmd}

        def #{cmd}(*args)
          f = Fiber.current
          cb = proc { |e, err|
            f.resume e || err
          }
          a#{cmd}(*args, &cb)

          response = Fiber.yield
          raise response if response.is_a?(StandardError)
          response
        end
      CODE
    end

  end
end

module Fraggle
  class Client

    %w{rev set get del stat getdir walk}.each do |cmd|
      class_eval <<-CODE
        alias :a#{cmd} :#{cmd}

        def #{cmd}(*args, &blk)
          f = Fiber.current
          blk = proc{ |v| v } if !block_given?
          cb = proc { |e, err|
            if err
              f.resume err
            else
              f.resume blk.call(e)
            end
          }
          a#{cmd}(*args, &cb)

          response = Fiber.yield
          raise response if response.is_a?(StandardError)
          response
        end
      CODE
    end

  end
end

Handle blocks passed to functions
Handle blocks passed to functions

This means we can implement getdir and walk.
