2020-10-25 15:59:40 -04:00
|
|
|
class ClosedQueueError < StandardError; end
|
|
|
|
module Puma
|
|
|
|
|
|
|
|
# Queue#close was added in Ruby 2.3.
|
|
|
|
# Add a simple implementation for earlier Ruby versions.
|
|
|
|
#
|
|
|
|
module QueueClose
|
|
|
|
def initialize
|
|
|
|
@closed = false
|
|
|
|
super
|
2020-10-06 09:22:53 -04:00
|
|
|
end
|
2020-10-25 15:59:40 -04:00
|
|
|
def close
|
|
|
|
@closed = true
|
|
|
|
end
|
|
|
|
def closed?
|
|
|
|
@closed
|
|
|
|
end
|
|
|
|
def push(object)
|
2020-10-25 18:07:43 -04:00
|
|
|
@closed ||= false
|
2020-10-25 15:59:40 -04:00
|
|
|
raise ClosedQueueError if @closed
|
|
|
|
super
|
|
|
|
end
|
|
|
|
alias << push
|
2020-10-06 09:22:53 -04:00
|
|
|
end
|
2020-10-25 15:59:40 -04:00
|
|
|
::Queue.prepend QueueClose
|
2020-10-06 09:22:53 -04:00
|
|
|
end
|