-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from julianghionoiu/fix-long-timeouts-test
Fix long timeouts test, adds performance test
- Loading branch information
Showing
5 changed files
with
74 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class ThreadTimer | ||
def initialize(timeout_millis, callback) | ||
@timeout_millis=timeout_millis | ||
@continue = true | ||
@callback = callback | ||
@timer_thread = nil | ||
end | ||
|
||
def start_timer | ||
@continue = true | ||
@timer_thread = Thread.new { start_timeout } | ||
end | ||
|
||
def stop_timer | ||
@continue = false | ||
@timer_thread.terminate unless @timer_thread.nil? | ||
@timer_thread = nil | ||
end | ||
|
||
private | ||
|
||
def start_timeout | ||
total_millis = 0 | ||
interval_millis = 10 | ||
while @continue && total_millis < @timeout_millis | ||
sleep interval_millis / 1000.00 | ||
total_millis += interval_millis | ||
end | ||
|
||
if total_millis >= @timeout_millis | ||
@callback.call | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters