From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id 3EA1117D4531 for ; Sun, 24 Nov 2013 13:58:27 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 11C05B5D836 for ; Sun, 24 Nov 2013 13:30:27 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 8F38597A834 for ; Sun, 24 Nov 2013 13:30:28 +0900 (JST) X-Virus-Scanned: amavisd-new at nagaokaut.ac.jp Received: from funfun.nagaokaut.ac.jp ([127.0.0.1]) by funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id c89dLKIKwq5Y for ; Sun, 24 Nov 2013 13:30:28 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 6E64897A82C for ; Sun, 24 Nov 2013 13:30:28 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 797CF95241A for ; Sun, 24 Nov 2013 13:30:21 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 0DA4112070E; Sun, 24 Nov 2013 13:30:11 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from fluorine.ruby-lang.org (fluorine.ruby-lang.org [210.251.121.216]) by neon.ruby-lang.org (Postfix) with ESMTP id 87F06120527 for ; Sun, 24 Nov 2013 13:30:08 +0900 (JST) Received: from ruby-lang.org (localhost [127.0.0.1]) by fluorine.ruby-lang.org (Postfix) with ESMTP id 682532920F for ; Sun, 24 Nov 2013 13:30:08 +0900 (JST) Date: Sun, 24 Nov 2013 13:30:08 +0900 From: "Glass_saga (Masaki Matsushita)" To: ruby-core@ruby-lang.org Message-Id: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 X-Redmine-Issue-Author: jsc X-Auto-Response-Suppress: OOF X-Redmine-Issue-Id: 9145 X-Redmine-Mailinglistintegration-Message-Ids: 32241 X-Mailer: Redmine X-Redmine-Project: ruby-trunk Auto-Submitted: auto-generated X-Redmine-Site: Ruby Issue Tracking System X-Redmine-Host: bugs.ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 58546 Subject: [ruby-core:58546] [ruby-trunk - Feature #9145][Feedback] Queue#pop(true) return nil if empty instead of raising ThreadError X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #9145 has been updated by Glass_saga (Masaki Matsushita). Category changed from lib to ext Status changed from Open to Feedback 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 ---------------------------------------- Feature #9145: Queue#pop(true) return nil if empty instead of raising ThreadError https://bugs.ruby-lang.org/issues/9145#change-43126 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/