70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97 
     | 
    
      # File 'common/jsonmodel_client.rb', line 70
def self.start_background_thread
  Thread.new do
    sequence = 0
    while true
      begin
        notifications = JSONModel::HTTP::get_json('/notifications',
                                                  :last_sequence => sequence)
        notifications.each do |notification|
          @@notification_handlers.each do |handler|
            if handler[:code].nil? or handler[:code] == notification["code"]
              begin
                handler[:block].call(notification["code"], notification["params"])
              rescue
                $stderr.puts("ERROR: Failed to handle notification #{notification.inspect}: #{$!}")
              end
            end
          end
        end
        sequence = notifications.last['sequence']
      rescue
        sleep 5
      end
    end
  end
end
     |