Project

General

Profile

Actions

Feature #17363

open

Timeouts

Added by marcandre (Marc-Andre Lafortune) almost 4 years ago. Updated over 2 years ago.

Status:
Assigned
Target version:
-
[ruby-core:101217]

Description

Builtin methods like Queue.pop and Ractor.receive have no timeout parameter.

We should either:

  • provide such a parameter
  • and/or provide a Timeout::wake that raises an timeout error only if the block is currently sleeping.

Details:

q = Queue.new
# ...
elem = Timeout::timeout(42) { q.pop } # => It is possible that an element is retreived from the queue but never stored in `elem`

elem = Timeout::wake(42) { q.pop } # => Guaranteed that either element is retrieved from the queue or an exception is raised, never both
Timeout::wake(42) { loop {} } # => infinite loop
# and/or
elem = q.pop(timeout: 42)

Currently, the only reliable way to have a Queue that accepts a timeout is to re-implement it from scratch. This post describe how involved that can be: https://spin.atomicobject.com/2017/06/28/queue-pop-with-timeout-fixed/


Related issues 3 (1 open2 closed)

Related to Ruby master - Feature #17470: Introduce non-blocking `Timeout.timeout`Closedioquatix (Samuel Williams)Actions
Related to Ruby master - Feature #17849: Fix Timeout.timeout so that it can be used in threaded Web serversAssignedmatz (Yukihiro Matsumoto)Actions
Related to Ruby master - Feature #18774: Add Queue#pop(timeout:)ClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0