njh / ruby-mqtt

Pure Ruby gem that implements the MQTT protocol, a lightweight protocol for publish/subscribe messaging.
http://www.rubydoc.info/gems/mqtt
MIT License
541 stars 135 forks source link

Is it working on a thread? #92

Closed neilyoung closed 7 years ago

neilyoung commented 7 years ago

The implementation seems to not work on a thread. Can you confirm?

Seems to not work for me:

MQTT::Client.connect('localhost') do |c|

  upload = Thread.new do 
    while true
      c.publish('/message', 'message')  
      sleep(1)  
    end

  end

end

Runs just once

neilyoung commented 7 years ago

Well, my bad. This works well:

Thread.new  do 
  # Publish example
  MQTT::Client.connect('localhost') do |c|
    while true
      c.publish('/message', 'message')  
      sleep(1)  
    end

  end

end