ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:109756] [Ruby master Feature#18982] Add an `exception: false` argument for Queue#push, Queue#pop, SizedQueue#push and SizedQueue#pop
@ 2022-08-29 10:20 byroot (Jean Boussier)
  2022-08-29 10:23 ` [ruby-core:109758] " byroot (Jean Boussier)
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: byroot (Jean Boussier) @ 2022-08-29 10:20 UTC (permalink / raw)
  To: ruby-core

Issue #18982 has been reported by byroot (Jean Boussier).

----------------------------------------
Feature #18982: Add an `exception: false` argument for Queue#push, Queue#pop, SizedQueue#push and SizedQueue#pop
https://bugs.ruby-lang.org/issues/18982

* Author: byroot (Jean Boussier)
* Status: Open
* Priority: Normal
----------------------------------------
This replaces [Feature #18965]

Currently these methods raise in three occasions:

  - `ThreadError(queue empty)` for `#pop` in `nonblock=true` mode, and the operation would block.
  - `ThreadError(queue full)` for `SizedQueue#push` in `nonblock=true` mode, and the operation would block.
  - `ClosedQueueError` if trying to `#push` in a closed queue.

I see several reasons to prefer a `nil` return value.

- Queue is often used in conjunction with threads, so you have to be very careful not to rescue an unrelated `ThreadError`.
- Queue if often used for low level code, deep in the stack, so exceptions are costly.

I propose that passing `exception: false` would cause the method to return `nil` instead of raising in the three cases listed above.

The argument `exception: true` is consistent with various other methods such as `IO#read_nonblock(exception: false)`.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-10-06  6:49 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-29 10:20 [ruby-core:109756] [Ruby master Feature#18982] Add an `exception: false` argument for Queue#push, Queue#pop, SizedQueue#push and SizedQueue#pop byroot (Jean Boussier)
2022-08-29 10:23 ` [ruby-core:109758] " byroot (Jean Boussier)
2022-08-29 10:24 ` [ruby-core:109759] " Eregon (Benoit Daloze)
2022-08-30  0:08 ` [ruby-core:109778] " shyouhei (Shyouhei Urabe)
2022-08-30  0:15 ` [ruby-core:109779] " byroot (Jean Boussier)
2022-08-30  0:42 ` [ruby-core:109780] " jeremyevans0 (Jeremy Evans)
2022-08-30  8:36 ` [ruby-core:109786] " shyouhei (Shyouhei Urabe)
2022-09-22  4:50 ` [ruby-core:109988] " ko1 (Koichi Sasada)
2022-09-22  6:46 ` [ruby-core:109990] " byroot (Jean Boussier)
2022-10-06  6:47 ` [ruby-core:110199] " ko1 (Koichi Sasada)
2022-10-06  6:49 ` [ruby-core:110200] " byroot (Jean Boussier)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).