require 'smoke/client/connection' module Smoke module Client class SignalRunner < Thread DEFAULT_OPTIONS = { :connection => Connection::DEFAULT_OPTIONS } # TODO: Make signals persistant in case the client dies. # TODO: Don't want to lose data, eh? attr_accessor :signals def initialize(options = {}) options.merge!(DEFAULT_OPTIONS) @connection = Connection.new(options[:connection]) @signals = [] super do # FIXME: This should be event driven rather than polling and sleeping. loop do if !signals.empty? # FIXME: Probably shouldn't remove from the store until after # processing. Refactoring this will mean refactoring #send_signal # as it re-inserts the signal if something goes wrong. send_signal(signals.shift) else sleep 0.5 end end end end def send_signal(signal) @connection.send_signal(signal) rescue signals.unshift signal end end end end