From: uwe@kubosch.no
To: ruby-core@ruby-lang.org
Subject: [ruby-core:84576] [Ruby trunk Feature#9145] Queue#pop(true) return nil if empty instead of raising ThreadError
Date: Mon, 01 Jan 2018 19:41:23 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-69116.20180101194122.31300f23fe7d6de3@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-9145.20131124124225@ruby-lang.org
Issue #9145 has been updated by uwe@kubosch.no (Uwe Kubosch).
How about a block form where the block is called with the popped element? The method would return false if called with non_block set to true if the queue is empty.
q = Queue.new
q << 1
q << 2
q << 3
while q.pop(true){|x| p x}
----------------------------------------
Feature #9145: Queue#pop(true) return nil if empty instead of raising ThreadError
https://bugs.ruby-lang.org/issues/9145#change-69116
* Author: jsc (Justin Collins)
* Status: Open
* Priority: Normal
* Assignee:
* 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.
--
https://bugs.ruby-lang.org/
prev parent reply other threads:[~2018-01-01 19: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 ` [ruby-core:58556] [ruby-trunk - Feature #9145] " jsc (Justin Collins)
2013-11-25 6:17 ` [ruby-core:58564] " 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 ` uwe [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-69116.20180101194122.31300f23fe7d6de3@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).