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 1AD1017D31CC for ; Mon, 25 Nov 2013 09:41:11 +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 4B273B5D842 for ; Mon, 25 Nov 2013 09:13:22 +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 414C397A834 for ; Mon, 25 Nov 2013 09:13:23 +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 MqfoCSdGVgJb for ; Mon, 25 Nov 2013 09:13:23 +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 1D73F97A82C for ; Mon, 25 Nov 2013 09:13:23 +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 EC75F952408 for ; Mon, 25 Nov 2013 09:13:21 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id EE63E1208CC; Mon, 25 Nov 2013 09:13:12 +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 3964B12087B for ; Mon, 25 Nov 2013 09:13:10 +0900 (JST) Received: from ruby-lang.org (localhost [127.0.0.1]) by fluorine.ruby-lang.org (Postfix) with ESMTP id 0B89F2517F for ; Mon, 25 Nov 2013 09:13:09 +0900 (JST) Date: Mon, 25 Nov 2013 09:13:09 +0900 From: "jsc (Justin Collins)" 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: 32252 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: 58556 Subject: [ruby-core:58556] [ruby-trunk - Feature #9145] 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 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/