diff options
| author | Masafumi Koba <473530+ybiquitous@users.noreply.github.com> | 2026-01-16 10:42:22 +0900 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2026-01-17 14:05:07 +0000 |
| commit | 81e06e7004ef17d50aa7ca9b26b31fb1ada515f8 (patch) | |
| tree | cfe611d7c6d736ee9e4287f6eb9e47e66f7f580b /lib | |
| parent | 78b7646bdb91285873ac26bca060591e06c45afe (diff) | |
[ruby/timeout] Improve Timeout.timeout documentation formatting and typos
This commit makes a few minor improvements to the documentation of the `Timeout.timeout` method.
The changes include fixing typos and enhancing formatting for better readability.
We can see the latest version of the documentation here:
https://docs.ruby-lang.org/en/master/Timeout.html#method-c-timeout
Also, we can verify this change locally by running:
```shell
rdoc
open doc/Timeout.html
```
https://github.com/ruby/timeout/commit/53ee559e15
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/timeout.rb | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/lib/timeout.rb b/lib/timeout.rb index 5d1f61d8af..e293e3be7c 100644 --- a/lib/timeout.rb +++ b/lib/timeout.rb @@ -212,17 +212,17 @@ module Timeout # value of 0 or +nil+ will execute the block without any timeout. # Any negative number will raise an ArgumentError. # +klass+:: Exception Class to raise if the block fails to terminate - # in +sec+ seconds. Omitting will use the default, Timeout::Error + # in +sec+ seconds. Omitting will use the default, Timeout::Error. # +message+:: Error message to raise with Exception Class. - # Omitting will use the default, "execution expired" + # Omitting will use the default, <tt>"execution expired"</tt>. # # Returns the result of the block *if* the block completed before # +sec+ seconds, otherwise raises an exception, based on the value of +klass+. # # The exception raised to terminate the given block is the given +klass+, or # Timeout::ExitException if +klass+ is not given. The reason for that behavior - # is that Timeout::Error inherits from RuntimeError and might be caught unexpectedly by `rescue`. - # Timeout::ExitException inherits from Exception so it will only be rescued by `rescue Exception`. + # is that Timeout::Error inherits from RuntimeError and might be caught unexpectedly by +rescue+. + # Timeout::ExitException inherits from Exception so it will only be rescued by <tt>rescue Exception</tt>. # Note that the Timeout::ExitException is translated to a Timeout::Error once it reaches the Timeout.timeout call, # so outside that call it will be a Timeout::Error. # @@ -231,7 +231,7 @@ module Timeout # For those reasons, this method cannot be relied on to enforce timeouts for untrusted blocks. # # If a scheduler is defined, it will be used to handle the timeout by invoking - # Scheduler#timeout_after. + # Fiber::Scheduler#timeout_after. # # Note that this is both a method of module Timeout, so you can <tt>include # Timeout</tt> into your classes so they have a #timeout method, as well as @@ -239,13 +239,13 @@ module Timeout # # ==== Ensuring the exception does not fire inside ensure blocks # - # When using Timeout.timeout it can be desirable to ensure the timeout exception does not fire inside an +ensure+ block. - # The simplest and best way to do so it to put the Timeout.timeout call inside the body of the begin/ensure/end: + # When using Timeout.timeout, it can be desirable to ensure the timeout exception does not fire inside an +ensure+ block. + # The simplest and best way to do so is to put the Timeout.timeout call inside the body of the +begin+/+ensure+/+end+: # # begin # Timeout.timeout(sec) { some_long_operation } # ensure - # cleanup # safe, cannot be interrupt by timeout + # cleanup # safe, cannot be interrupted by timeout # end # # If that is not feasible, e.g. if there are +ensure+ blocks inside +some_long_operation+, @@ -263,17 +263,17 @@ module Timeout # end # } # - # An important thing to note is the need to pass an exception klass to Timeout.timeout, - # otherwise it does not work. Specifically, using +Thread.handle_interrupt(Timeout::ExitException => ...)+ + # An important thing to note is the need to pass an exception +klass+ to Timeout.timeout, + # otherwise it does not work. Specifically, using <tt>Thread.handle_interrupt(Timeout::ExitException => ...)</tt> # is unsupported and causes subtle errors like raising the wrong exception outside the block, do not use that. # # Note that Thread.handle_interrupt is somewhat dangerous because if setup or cleanup hangs # then the current thread will hang too and the timeout will never fire. # Also note the block might run for longer than +sec+ seconds: - # e.g. some_long_operation executes for +sec+ seconds + whatever time cleanup takes. + # e.g. +some_long_operation+ executes for +sec+ seconds + whatever time cleanup takes. # - # If you want the timeout to only happen on blocking operations one can use :on_blocking - # instead of :immediate. However, that means if the block uses no blocking operations after +sec+ seconds, + # If you want the timeout to only happen on blocking operations, one can use +:on_blocking+ + # instead of +:immediate+. However, that means if the block uses no blocking operations after +sec+ seconds, # the block will not be interrupted. def self.timeout(sec, klass = nil, message = nil, &block) #:yield: +sec+ return yield(sec) if sec == nil or sec.zero? |
