lib/polyphony/core/timer.rb
# call-seq:
#   timer.cancel_after(interval) { ... }
#   timer.cancel_after(interval, with_exception: exception) { ... }
#   timer.cancel_after(interval, with_exception: [klass, message]) { ... }
#   timer.cancel_after(interval) { |timeout| ... }
#   timer.cancel_after(interval, with_exception: exception) { |timeout| ... }
#   timer.cancel_after(interval, with_exception: [klass, message]) { |timeout| ... }
#
# Runs the given block after setting up a cancellation timer for
# cancellation. If the cancellation timer elapses, the execution will be
# interrupted with an exception defaulting to `Polyphony::Cancel`.
#
# This method should be used when a timeout should cause an exception to be
# propagated down the call stack or up the fiber tree.
#
# Example of normal use:
#
#   def read_from_io_with_timeout(io)
#     timer.cancel_after(10) { io.read }
#   rescue Polyphony::Cancel
#     nil
#   end
#
# The timeout period can be reset using `Timer#reset`, as shown in the
# following example:
#
#   timer.cancel_after(10) do
#     loop do
#       msg = socket.gets
#       timer.reset
#       handle_msg(msg)
#     end
#   end
#
# @param interval [Number] timout in seconds
# @param with_exception: [Class, Exception] exception or exception class
# @param &block [Proc] block to execute
# @return [any] block's return value


Runs the given block after setting up a cancellation timer for
cancellation. If the cancellation timer elapses, the execution will be
interrupted with an exception defaulting to `Polyphony::Cancel`.

This method should be used when a timeout should cause an exception to be
propagated down the call stack or up the fiber tree.

Example of normal use.



The timeout period can be reset using `Timer#reset`, as shown in the
following example.


Runs the given block after setting up a cancellation timer for cancellation . If the cancellation timer elapses the execution will be interrupted with an exception defaulting to ` Polyphony :: Cancel ` . This method should be used when a timeout should cause an exception to be propagated down the call stack or up the fiber tree . Example of normal use . The timeout period can be reset using ` Timer#reset ` as shown in the following example .
def cancel_after(interval, with_exception: Polyphony::Cancel)
      fiber = Fiber.current
      @timeouts[fiber] = {
        interval: interval,
        target_stamp: now + interval,
        exception: with_exception
      }
      yield
    ensure
      @timeouts.delete(fiber)
    end
def cancel_after ( interval , with_exception : Polyphony :: Cancel ) fiber = Fiber . current @timeouts [ fiber ] = { interval : interval , target_stamp : now + interval , exception : with_exception } yield ensure @timeouts . delete ( fiber ) end
call-seq:
timer.cancel_after(interval) { ... }
timer.cancel_after(interval, with_exception: exception) { ... }
timer.cancel_after(interval, with_exception: [klass, message]) { ... }
timer.cancel_after(interval) { |timeout| ... }
timer.cancel_after(interval, with_exception: exception) { |timeout| ... }
timer.cancel_after(interval, with_exception: [klass, message]) { |timeout| ... }
call - seq : timer . cancel_after ( interval ) { ... } timer . cancel_after ( interval with_exception : exception ) { ... } timer . cancel_after ( interval with_exception : [ klass message ] ) { ... } timer . cancel_after ( interval ) { |timeout| ... } timer . cancel_after ( interval with_exception : exception ) { |timeout| ... } timer . cancel_after ( interval with_exception : [ klass message ] ) { |timeout| ... }
block's return value
block ' s return value
any
interval
timout in seconds
timout in seconds
with_exception
<not_specific>
with_exception:
<not_specific>
exception or exception class
exception or exception class
&block
<not_specific>
block to execute
block to execute