ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "byroot (Jean Boussier)" <noreply@ruby-lang.org>
To: ruby-core@neon.ruby-lang.org
Subject: [ruby-core:110200] [Ruby master Feature#18982] Add an `exception: false` argument for Queue#push, Queue#pop, SizedQueue#push and SizedQueue#pop
Date: Thu, 06 Oct 2022 06:49:22 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-99482.20221006064922.7941@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-18982.20220829102034.7941@ruby-lang.org

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


Works for me. I'll leave this ticket open until I add some more spec and documentation to the existing method.

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

* 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/

      parent reply	other threads:[~2022-10-06  6:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` byroot (Jean Boussier) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-99482.20221006064922.7941@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    --cc=ruby-core@neon.ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).