Sha256: aadccb5dbda09f217cd4fdf49f26fe5edf9ca7781c9f930c9170d8efb205a153
Contents?: true
Size: 615 Bytes
Versions: 8
Compression:
Stored size: 615 Bytes
Contents
class RestCore::Timeout::TimerThread attr_accessor :timeout, :error def initialize timeout, error, &block t = Thread.current self.timeout = timeout self.error = error self.block = block || lambda{ t.raise error } @canceled = false start end def on_timeout &block self.block = block end def cancel @canceled = true end def canceled? @canceled end def start return if timeout.nil? || timeout.zero? self.thread = Thread.new{ sleep(timeout) block.call unless canceled? } end protected attr_accessor :block, :thread end
Version data entries
8 entries across 8 versions & 1 rubygems