aboutsummaryrefslogtreecommitdiff
path: root/src/internal/timer.rs
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-13 19:28:13 -0800
committerAustin Hellyer <[email protected]>2016-11-14 18:32:10 -0800
commit7d22fb2a9c70e5e517b359875a0157f72e352e43 (patch)
treeca3bcb3a76f68960563d3c38d45e21f493ce32f8 /src/internal/timer.rs
parentAdd internal module (diff)
downloadserenity-7d22fb2a9c70e5e517b359875a0157f72e352e43.tar.xz
serenity-7d22fb2a9c70e5e517b359875a0157f72e352e43.zip
Add voice connection support
Diffstat (limited to 'src/internal/timer.rs')
-rw-r--r--src/internal/timer.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/internal/timer.rs b/src/internal/timer.rs
new file mode 100644
index 0000000..cc846b3
--- /dev/null
+++ b/src/internal/timer.rs
@@ -0,0 +1,45 @@
+use std::thread;
+use std::time::Duration as StdDuration;
+use time::{self, Duration, Timespec};
+
+pub struct Timer {
+ due: Timespec,
+ duration: Duration,
+}
+
+impl Timer {
+ pub fn new(duration_in_ms: u64) -> Timer {
+ let duration = Duration::milliseconds(duration_in_ms as i64);
+
+ Timer {
+ due: time::get_time() + duration,
+ duration: duration,
+ }
+ }
+
+ pub fn await(&mut self) {
+ let diff = self.due - time::get_time();
+
+ if diff > time::Duration::zero() {
+ let amount = diff.num_milliseconds() as u64;
+
+ thread::sleep(StdDuration::from_millis(amount));
+ }
+
+ self.due = self.due + self.duration;
+ }
+
+ pub fn check(&mut self) -> bool {
+ if time::get_time() >= self.due {
+ self.due = self.due + self.duration;
+
+ true
+ } else {
+ false
+ }
+ }
+
+ pub fn reset(&mut self) {
+ self.due = time::get_time() + self.duration;
+ }
+}