Feature #21821
openAdd Stack and SizedStack classes
Description
Context¶
Queue and SizedQueue are very useful and performant constructs, however they only allow for FIFO queues.
Some use cases do call for LIFO queues AKA stacks.
For instance, in the case of connection pool, it's often preferable to use a stack.
Feature¶
I'd like to introduce Stack and SizedStack classes, to mirror Queue and SizedQueue.
They'd have exactly the same method and behavior at the exception of dequeuing order.
Thread namespace?¶
Currently Queue and SizedQueue are technically defined under Thread and aliased in Object.
I wonder if that's something we should do for Stack too, or just some historical thing we shouldn't perpetuate.
Updated by byroot (Jean Boussier) 2 days ago
- Related to Feature #21721: Allow `Queue` and `SizedQueue` to be used as LIFO queues added
Updated by nobu (Nobuyoshi Nakada) 2 days ago
byroot (Jean Boussier) wrote:
Currently
QueueandSizedQueueare technically defined underThreadand aliased inObject.
I wonder if that's something we should do forStacktoo, or just some historical thing we shouldn't perpetuate.
I think it will depend on what you achieve with Stack.
If you want to use it for inter thread communication, Thread namespace should be suitable.
Otherwise, if you want just simple push/pop operations, why isn't Array enough?
Updated by byroot (Jean Boussier) 2 days ago
I think it will depend on what you achieve with Stack.
Yes, the point is to use it in cases where synchronization is needed, hence Array is not suitable. Typically connection pools: https://github.com/mperham/connection_pool/blob/8ba2715edca69d6162fd4f798997b74dd64e9529/lib/connection_pool/timed_stack.rb