-
Notifications
You must be signed in to change notification settings - Fork 987
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
runtime: Don't disable timeout due to ipfs.map
- Loading branch information
Showing
2 changed files
with
86 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copied from https://github.com/ellisonch/rust-stopwatch | ||
// Copyright (c) 2014 Chucky Ellison <cme at freefour.com> under MIT license | ||
|
||
use std::default::Default; | ||
use std::time::{Duration, Instant}; | ||
|
||
#[derive(Clone, Copy)] | ||
pub struct TimeoutStopwatch { | ||
/// The time the stopwatch was started last, if ever. | ||
start_time: Option<Instant>, | ||
/// The time the stopwatch was split last, if ever. | ||
split_time: Option<Instant>, | ||
/// The time elapsed while the stopwatch was running (between start() and stop()). | ||
elapsed: Duration, | ||
} | ||
|
||
impl Default for TimeoutStopwatch { | ||
fn default() -> TimeoutStopwatch { | ||
TimeoutStopwatch { | ||
start_time: None, | ||
split_time: None, | ||
elapsed: Duration::from_secs(0), | ||
} | ||
} | ||
} | ||
|
||
impl TimeoutStopwatch { | ||
/// Returns a new stopwatch. | ||
pub fn new() -> TimeoutStopwatch { | ||
let sw: TimeoutStopwatch = Default::default(); | ||
return sw; | ||
} | ||
|
||
/// Returns a new stopwatch which will immediately be started. | ||
pub fn start_new() -> TimeoutStopwatch { | ||
let mut sw = TimeoutStopwatch::new(); | ||
sw.start(); | ||
return sw; | ||
} | ||
|
||
/// Starts the stopwatch. | ||
pub fn start(&mut self) { | ||
self.start_time = Some(Instant::now()); | ||
} | ||
|
||
/// Stops the stopwatch. | ||
pub fn stop(&mut self) { | ||
self.elapsed = self.elapsed(); | ||
self.start_time = None; | ||
self.split_time = None; | ||
} | ||
|
||
/// Returns the elapsed time since the start of the stopwatch. | ||
pub fn elapsed(&self) -> Duration { | ||
match self.start_time { | ||
// stopwatch is running | ||
Some(t1) => { | ||
return t1.elapsed() + self.elapsed; | ||
} | ||
// stopwatch is not running | ||
None => { | ||
return self.elapsed; | ||
} | ||
} | ||
} | ||
} |