Skip to content

Instantly share code, notes, and snippets.

@kirillshevch
Last active December 22, 2020 07:42
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
class App
attr_reader :queue
def initialize
@queue = []
end
def call
puts "App PID: #{Process.pid}"
publish
subscribe
end
private
def subscribe
loop do
puts 'Pop: ' + queue.pop.to_s
sleep(2)
end
end
def publish
Thread.new do
loop do
number = rand(0..9)
queue.push(number)
puts 'Queue: ' + queue.to_s
sleep(1)
end
end
end
end
app = App.new
Signal.trap('TERM') do
puts 'Received Signal'
puts 'Process the remaining messages:'
app.queue.each { |m| puts m }
exit
end
app.call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment