def realtime_block(key, &block)
      hash = current_realtime

      if in_realtime_block?
        ret = realtime_store(hash, key, &block)
        return ret, hash
      else
        begin
          self.current_realtime = hash
          begin
            ret = realtime_store(hash, key, &block)
            return ret, hash
          rescue Exception => err # rubocop:disable Lint/RescueException
            err.define_singleton_method(:timings) { hash } unless err.respond_to?(:timings)
            raise
          ensure
            delete_current_realtime
          end
        ensure
          # A second layer of protection in case Timeout::Error struck right after
          # setting self.current_realtime, or right before `delete_current_realtime`.
          # In those cases, current_realtime might (wrongly) still exist.
          delete_current_realtime if in_realtime_block?
        end
      end
    end
def realtime_block(key, &block)
      hash = current_realtime

      if in_realtime_block?
        ret = realtime_store(hash, key, &block)
        return ret, hash
      else
        begin
          self.current_realtime = hash
          begin
            ret = realtime_store(hash, key, &block)
            return ret, hash
          rescue Exception => err # rubocop:disable Lint/RescueException
            err.define_singleton_method(:timings) { hash } unless err.respond_to?(:timings)
            raise
          ensure
            delete_current_realtime
          end
        ensure
          # A second layer of protection in case Timeout::Error struck right after
          # setting self.current_realtime, or right before `delete_current_realtime`.
          # In those cases, current_realtime might (wrongly) still exist.
          delete_current_realtime if in_realtime_block?
        end
      end
    end
Stores the elapsed real time used to execute the given block for the given
 key and returns the hash as well as the result from the block.  The hash is
 stored globally, keyed on thread id, and is cleared once the topmost nested
 call completes.  If the hash already has a value for that key, the time is
 accumulated.

   Benchmark.realtime_block(:sleep) do
     sleep 2
     "foo"
   end # => ["foo", {:sleep => 2.00}]

   Benchmark.realtime_block(:outer_sleep) do
     sleep 2
     Benchmark.realtime_block(:inner_sleep) { sleep 2 }
     "bar"
   end # => ["bar", {:inner_sleep => 2.00, :outer_sleep => 4.00}]

   Benchmark.realtime_block(:outer_sleep) do
     sleep 2
     2.times do
       Benchmark.realtime_block(:inner_sleep) { sleep 2 }
     end
     "baz"
   end # => ["baz", {:inner_sleep => 4.00, :outer_sleep => 6.00}]