lib/polyphony/core/global_api.rb
# call-seq:
#   cancel_after(interval) { ... }
#   cancel_after(interval, with_exception: exception) { ... }
#   cancel_after(interval, with_exception: [klass, message]) { ... }
#   cancel_after(interval) { |timeout| ... }
#   cancel_after(interval, with_exception: exception) { |timeout| ... }
#   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)
#     cancel_after(10) { io.read }
#   rescue Polyphony::Cancel
#     nil
#   end
#
# The timeout period can be reset by passing a block that takes a single
# argument. The block will be provided with the canceller fiber. To reset
# the timeout, use `Fiber#reset`, as shown in the following example:
#
#   cancel_after(10) do |timeout|
#     loop do
#       msg = socket.gets
#       timeout.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 by passing a block that takes a single
argument. The block will be provided with the canceller fiber. To reset
the timeout, use `Fiber#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 by passing a block that takes a single argument . The block will be provided with the canceller fiber . To reset the timeout use ` Fiber#reset ` as shown in the following example .
def cancel_after(interval, with_exception: Polyphony::Cancel, &block)
      if block.arity > 0
        cancel_after_with_optional_reset(interval, with_exception, &block)
      else
        Polyphony.backend_timeout(interval, with_exception, &block)
      end
    end
def cancel_after ( interval , with_exception : Polyphony :: Cancel , & block ) if block . arity > 0 cancel_after_with_optional_reset ( interval , with_exception , & block ) else Polyphony . backend_timeout ( interval , with_exception , & block ) end end
call-seq:
cancel_after(interval) { ... }
cancel_after(interval, with_exception: exception) { ... }
cancel_after(interval, with_exception: [klass, message]) { ... }
cancel_after(interval) { |timeout| ... }
cancel_after(interval, with_exception: exception) { |timeout| ... }
cancel_after(interval, with_exception: [klass, message]) { |timeout| ... }
call - seq : cancel_after ( interval ) { ... } cancel_after ( interval with_exception : exception ) { ... } cancel_after ( interval with_exception : [ klass message ] ) { ... } cancel_after ( interval ) { |timeout| ... } cancel_after ( interval with_exception : exception ) { |timeout| ... } 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>
block
<not_specific>
with_exception:
<not_specific>
exception or exception class
exception or exception class
&block
<not_specific>
block to execute
block to execute