Class: Dhall::Util::Deadline

Inherits:
Object
  • Object
show all
Defined in:
lib/dhall/util.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(deadline) ⇒ Deadline

Returns a new instance of Deadline.



93
94
95
# File 'lib/dhall/util.rb', line 93

def initialize(deadline)
	@deadline = deadline
end

Class Method Details

.for_timeout(timeout) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/dhall/util.rb', line 85

def self.for_timeout(timeout)
	if timeout.nil? || timeout.to_f.infinite?
		NoDeadline.new
	else
		new(Time.now + timeout)
	end
end

Instance Method Details

#exceeded?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/dhall/util.rb', line 97

def exceeded?
	@deadline < Time.now
end

#timeoutObject



101
102
103
# File 'lib/dhall/util.rb', line 101

def timeout
	[0.000000000000001, @deadline - Time.now].max
end

#timeout_block(&block) ⇒ Object



105
106
107
# File 'lib/dhall/util.rb', line 105

def timeout_block(&block)
	Timeout.timeout(timeout, TimeoutException, &block)
end