From: "jsc (Justin Collins)" <redmine@ruby-lang.org>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:58556] [ruby-trunk - Feature #9145] Queue#pop(true) return nil if empty instead of raising ThreadError
Date: Mon, 25 Nov 2013 09:13:09 +0900 [thread overview]
Message-ID: <redmine.journal-43134.20131125091308@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-9145.20131124124225@ruby-lang.org
Issue #9145 has been updated by jsc (Justin Collins).
Glass_saga (Masaki Matsushita) wrote:
> I think we can't change default behavior of Queue#pop(true) because some code expects ThreadError to be raised.
> However, it may be possible to introduce new keyword argument like following:
>
> q = Queue.new
> while next_item = q.pop(true, exception: false) # it doesn't raise ThreadError and returns nil.
> # do something
> end
That would work for me.
----------------------------------------
Feature #9145: Queue#pop(true) return nil if empty instead of raising ThreadError
https://bugs.ruby-lang.org/issues/9145#change-43134
Author: jsc (Justin Collins)
Status: Feedback
Priority: Normal
Assignee:
Category: ext
Target version:
I propose the non-blocking form of Queue#pop behave like Array#pop and return nil when empty.
Current behavior is to raise a ThreadError, with a message indicating the queue is empty.
For example:
q = Queue.new
begin
loop do
next_item = q.pop(true)
end
rescue ThreadError
# queue is empty...or maybe something bad happened
end
Instead, this could be
q = Queue.new
while next_item = q.pop(true)
end
Alternatively, raise an exception that is a subclass of ThreadError with a more specific name, such as "QueueEmpty". This would be a small improvement while remaining compatible with existing code.
--
http://bugs.ruby-lang.org/
next prev parent reply other threads:[~2013-11-25 0:41 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-24 3:42 [ruby-core:58545] [ruby-trunk - Feature #9145][Open] Queue#pop(true) return nil if empty instead of raising ThreadError jsc (Justin Collins)
2013-11-24 4:30 ` [ruby-core:58546] [ruby-trunk - Feature #9145][Feedback] " Glass_saga (Masaki Matsushita)
2013-11-24 4:42 ` [ruby-core:58547] " Eric Wong
2013-11-25 2:55 ` [ruby-core:58562] " Joel VanderWerf
2013-11-25 0:13 ` jsc (Justin Collins) [this message]
2013-11-25 6:17 ` [ruby-core:58564] [ruby-trunk - Feature #9145] " drbrain (Eric Hodel)
2017-06-22 7:23 ` [ruby-core:81738] [Ruby trunk Feature#9145][Closed] " glass.saga
2017-06-22 7:44 ` [ruby-core:81739] " Eric Wong
2018-01-01 19:41 ` [ruby-core:84576] [Ruby trunk Feature#9145] " uwe
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-43134.20131125091308@ruby-lang.org \
--to=ruby-core@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).