Skip to content

Commit 81e06e7

Browse files
ybiquitousmatzbot
authored andcommitted
[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 ``` ruby/timeout@53ee559e15
1 parent 78b7646 commit 81e06e7

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

lib/timeout.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,17 @@ def self.synchronize(mutex, &block)
212212
# value of 0 or +nil+ will execute the block without any timeout.
213213
# Any negative number will raise an ArgumentError.
214214
# +klass+:: Exception Class to raise if the block fails to terminate
215-
# in +sec+ seconds. Omitting will use the default, Timeout::Error
215+
# in +sec+ seconds. Omitting will use the default, Timeout::Error.
216216
# +message+:: Error message to raise with Exception Class.
217-
# Omitting will use the default, "execution expired"
217+
# Omitting will use the default, <tt>"execution expired"</tt>.
218218
#
219219
# Returns the result of the block *if* the block completed before
220220
# +sec+ seconds, otherwise raises an exception, based on the value of +klass+.
221221
#
222222
# The exception raised to terminate the given block is the given +klass+, or
223223
# Timeout::ExitException if +klass+ is not given. The reason for that behavior
224-
# is that Timeout::Error inherits from RuntimeError and might be caught unexpectedly by `rescue`.
225-
# Timeout::ExitException inherits from Exception so it will only be rescued by `rescue Exception`.
224+
# is that Timeout::Error inherits from RuntimeError and might be caught unexpectedly by +rescue+.
225+
# Timeout::ExitException inherits from Exception so it will only be rescued by <tt>rescue Exception</tt>.
226226
# Note that the Timeout::ExitException is translated to a Timeout::Error once it reaches the Timeout.timeout call,
227227
# so outside that call it will be a Timeout::Error.
228228
#
@@ -231,21 +231,21 @@ def self.synchronize(mutex, &block)
231231
# For those reasons, this method cannot be relied on to enforce timeouts for untrusted blocks.
232232
#
233233
# If a scheduler is defined, it will be used to handle the timeout by invoking
234-
# Scheduler#timeout_after.
234+
# Fiber::Scheduler#timeout_after.
235235
#
236236
# Note that this is both a method of module Timeout, so you can <tt>include
237237
# Timeout</tt> into your classes so they have a #timeout method, as well as
238238
# a module method, so you can call it directly as Timeout.timeout().
239239
#
240240
# ==== Ensuring the exception does not fire inside ensure blocks
241241
#
242-
# When using Timeout.timeout it can be desirable to ensure the timeout exception does not fire inside an +ensure+ block.
243-
# The simplest and best way to do so it to put the Timeout.timeout call inside the body of the begin/ensure/end:
242+
# When using Timeout.timeout, it can be desirable to ensure the timeout exception does not fire inside an +ensure+ block.
243+
# The simplest and best way to do so is to put the Timeout.timeout call inside the body of the +begin+/+ensure+/+end+:
244244
#
245245
# begin
246246
# Timeout.timeout(sec) { some_long_operation }
247247
# ensure
248-
# cleanup # safe, cannot be interrupt by timeout
248+
# cleanup # safe, cannot be interrupted by timeout
249249
# end
250250
#
251251
# If that is not feasible, e.g. if there are +ensure+ blocks inside +some_long_operation+,
@@ -263,17 +263,17 @@ def self.synchronize(mutex, &block)
263263
# end
264264
# }
265265
#
266-
# An important thing to note is the need to pass an exception klass to Timeout.timeout,
267-
# otherwise it does not work. Specifically, using +Thread.handle_interrupt(Timeout::ExitException => ...)+
266+
# An important thing to note is the need to pass an exception +klass+ to Timeout.timeout,
267+
# otherwise it does not work. Specifically, using <tt>Thread.handle_interrupt(Timeout::ExitException => ...)</tt>
268268
# is unsupported and causes subtle errors like raising the wrong exception outside the block, do not use that.
269269
#
270270
# Note that Thread.handle_interrupt is somewhat dangerous because if setup or cleanup hangs
271271
# then the current thread will hang too and the timeout will never fire.
272272
# Also note the block might run for longer than +sec+ seconds:
273-
# e.g. some_long_operation executes for +sec+ seconds + whatever time cleanup takes.
273+
# e.g. +some_long_operation+ executes for +sec+ seconds + whatever time cleanup takes.
274274
#
275-
# If you want the timeout to only happen on blocking operations one can use :on_blocking
276-
# instead of :immediate. However, that means if the block uses no blocking operations after +sec+ seconds,
275+
# If you want the timeout to only happen on blocking operations, one can use +:on_blocking+
276+
# instead of +:immediate+. However, that means if the block uses no blocking operations after +sec+ seconds,
277277
# the block will not be interrupted.
278278
def self.timeout(sec, klass = nil, message = nil, &block) #:yield: +sec+
279279
return yield(sec) if sec == nil or sec.zero?

0 commit comments

Comments
 (0)