Good with some research and debugging. I can fix this problem. This problem occurred because, by default, Ruby operations are asynchronous. Therefore, the script is completed before the publication is complete. Fortunately, we have the http_sync option for this pubnub publishing method. By setting it to true, make sure that this thread is not completed before the publication is complete. So the new code
$pubnub.publish( http_sync: true, channel: "chat_ABC", message: message ) do |env| puts env.parsed_response end
source share