CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/support/acceptance/countdown.rb
Views: 1904
1
module Acceptance
2
###
3
# A utility class which can be used in conjunction with Timeout mechanisms
4
###
5
class Countdown
6
# @param [int] timeout The time in seconds that this count starts from
7
def initialize(timeout)
8
@start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :second)
9
@end_time = @start_time + timeout
10
@timeout = timeout
11
end
12
13
# @return [TrueClass, FalseClass] True if the timeout has surpassed, false otherwise
14
def elapsed?
15
remaining_time == 0
16
end
17
18
# @return [Integer] The time in seconds left before this countdown expires
19
def remaining_time
20
[@end_time - Process.clock_gettime(Process::CLOCK_MONOTONIC, :second), 0].max
21
end
22
end
23
end
24
25