From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-2.9 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED,SPF_PASS,T_RP_MATCHES_RCVD shortcircuit=no autolearn=no autolearn_force=no version=3.4.0 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 55CE01F404 for ; Mon, 1 Jan 2018 19:41:33 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id BE16F120A0D; Tue, 2 Jan 2018 04:41:30 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 13C051209FF for ; Tue, 2 Jan 2018 04:41:26 +0900 (JST) Received: by filter0025p3mdw1.sendgrid.net with SMTP id filter0025p3mdw1-23352-5A4A8EE3-5 2018-01-01 19:41:23.069344514 +0000 UTC Received: from herokuapp.com (ec2-54-144-232-149.compute-1.amazonaws.com [54.144.232.149]) by ismtpd0005p1iad1.sendgrid.net (SG) with ESMTP id 0EYAvFaxSkmVqHqBSVOhnA Mon, 01 Jan 2018 19:41:23.053 +0000 (UTC) Date: Mon, 01 Jan 2018 19:41:23 +0000 (UTC) From: uwe@kubosch.no To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 59771 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 9145 X-Redmine-Issue-Author: jsc X-Redmine-Sender: uwe@kubosch.no X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS6PkVeYPoMueUVemcqgD4uk2A6mbYGTUSdk6F FGnrPxgo+zAdtyALRKkbfQ3B6g+e28nX+1BPPjH1p+fXOuG8ZiDTVwSRI4lLGkkyla9rJFs5IrAAzT Zc0J46wDv3x13eBF0mVICX4gBAtE7EGcTmFE X-ML-Name: ruby-core X-Mail-Count: 84576 Subject: [ruby-core:84576] [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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" 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/