diff --git a/lib/blather_notify.rb b/lib/blather_notify.rb index b1aaa396b58767871d10b34ef8f7b34920428d84..5d801e954f74622eb4c6c477e4eae3d8cc41ab17 100644 --- a/lib/blather_notify.rb +++ b/lib/blather_notify.rb @@ -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