From: eregontp@... Date: 2020-12-03T19:04:33+00:00 Subject: [ruby-core:101224] [Ruby master Feature#17363] Timeouts Issue #17363 has been updated by Eregon (Benoit Daloze). +1 for `Queue#pop(timeout: 42)`. FWIW TruffleRuby already has `Queue#receive_timeout` as a private method, and this is used to implement `Timeout.timeout` without creating a new Thread every time. --- It sounds like the proposed `Timeout.wake{}` would be similar to `Thread#wakeup`. I'm not sure how it could work, because reading another thread state is always racy (without a GIL), and the thread checking timeouts must be a separate thread than the one doing the blocking call. Also it could interrupt a blocking call in `ensure` (e.g., cleaning up a connection), which would be unwanted. ---------------------------------------- Feature #17363: Timeouts https://bugs.ruby-lang.org/issues/17363#change-88907 * Author: marcandre (Marc-Andre Lafortune) * Status: Open * Priority: Normal ---------------------------------------- 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: ```ruby 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/ -- https://bugs.ruby-lang.org/ Unsubscribe: