1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00
puma--puma/lib/puma/queue_close.rb
Will Jordan ff17194228
Refactor drain on shutdown (#2600)
* Refactor test_puma_server#server_run for option arguments

* Refactor drain_on_shutdown into main server accept loop
Also add test coverage for drain_on_shutdown option.
2021-04-30 17:22:59 -05:00

26 lines
544 B
Ruby

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 close
num_waiting.times {push nil}
@closed = true
end
def closed?
@closed ||= false
end
def push(object)
raise ClosedQueueError if closed?
super
end
alias << push
def pop(non_block=false)
return nil if !non_block && closed? && empty?
super
end
end
::Queue.prepend QueueClose
end