Skip to content

Commit 542c739

Browse files
committed
Add Async::Clock#reset!.
1 parent eff526c commit 542c739

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/async/clock.rb

+9
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,14 @@ def total
6161

6262
return total
6363
end
64+
65+
# Reset the total elapsed time. If the clock is currently running, reset the start time to now.
66+
def reset!
67+
@total = 0
68+
69+
if @started
70+
@started = Clock.now
71+
end
72+
end
6473
end
6574
end

test/async/clock.rb

+18
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,22 @@
5858
expect(total).to be >= 0.0
5959
end
6060
end
61+
62+
with "#reset!" do
63+
it "resets the total time" do
64+
clock.start!
65+
sleep(0.0001)
66+
clock.stop!
67+
expect(clock.total).to be > 0.0
68+
clock.reset!
69+
expect(clock.total).to be == 0.0
70+
end
71+
72+
it "resets the start time" do
73+
clock.start!
74+
clock.reset!
75+
sleep(0.0001)
76+
expect(clock.total).to be > 0.0
77+
end
78+
end
6179
end

0 commit comments

Comments
 (0)