Project

General

Profile

Actions

Feature #18982

closed

Add an `exception: false` argument for Queue#push, Queue#pop, SizedQueue#push and SizedQueue#pop

Added by byroot (Jean Boussier) over 2 years ago. Updated about 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:109756]

Description

This replaces [Feature #18965]

Currently these methods raise in three occasions:

  • ThreadError(queue empty) for #pop in nonblock=true mode, and the operation would block.
  • ThreadError(queue full) for SizedQueue#push in nonblock=true mode, and the operation would block.
  • ClosedQueueError if trying to #push in a closed queue.

I see several reasons to prefer a nil return value.

  • Queue is often used in conjunction with threads, so you have to be very careful not to rescue an unrelated ThreadError.
  • Queue if often used for low level code, deep in the stack, so exceptions are costly.

I propose that passing exception: false would cause the method to return nil instead of raising in the three cases listed above.

The argument exception: true is consistent with various other methods such as IO#read_nonblock(exception: false).


Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #18965: Further Thread::Queue improvementsRejectedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0