Feature #11518

Queue enhancement - promote! and promote_all!

Added by jonathanscruz (Jonathan Cruz) over 4 years ago. Updated over 4 years ago.

Target version:


I’m submitting a patch to enhance the Queue class by adding the methods Queue#promote! and Queue#promote_all!. These methods require a block that accepts queue elements. Elements for which the block returns a truthy value are moved to the ‘front’ of the queue. Queue#promote! only applies to the first such element and Queue#promote_all! applies to all matching elements (preserving their relative order).

Motivation for this enhancement: Our project has several worker threads working on long-running work units in a queue, trying to find a ‘match’. The queue is pre-sorted with the most likely matches at the front and least likely at the back. However, there are cases where as we work on some elements, we gain new data that certain elements are more likely to match than we originally thought. We need a way to promote these elements to the front of the queue.


ruby_queue_promote.patch (2.82 KB) ruby_queue_promote.patch jonathanscruz (Jonathan Cruz), 09/09/2015 03:04 PM

Also available in: Atom PDF