~singpolyma/jmp-pay

b99296beac9c4e18b0d307805c49badb3b9571fd — Stephen Paul Weber 2 years ago 7b86f94
Fix intermittent notification non-delivery

We need to wait until all EventMachine items in flight are complete before we
allow the process to terminate or some of them might not happen.  So when the
process wants to exit, wait until the EM thread is done.  Use next_tick to make
sure our stop command only happens when the EM queue is next clear.
1 files changed, 10 insertions(+), 2 deletions(-)

M lib/blather_notify.rb
M lib/blather_notify.rb => lib/blather_notify.rb +10 -2
@@ 15,14 15,22 @@ module BlatherNotify
		setup(jid, password, nil, nil, nil, nil, workqueue_count: 0)

		EM.error_handler { |e| warn e.message }
		Thread.new do
		@thread = Thread.new do
			EM.run do
				client.run
			end
		end

		at_exit { shutdown }
		at_exit { wait_then_exit }

		Timeout.timeout(30) { @ready.pop }
	end

	def self.wait_then_exit
		EM.next_tick do
			shutdown
			EM.stop
		end
		@thread.join
	end
end