aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/horribly_inefficient_timers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/horribly_inefficient_timers.rs')
-rw-r--r--components/script/horribly_inefficient_timers.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/components/script/horribly_inefficient_timers.rs b/components/script/horribly_inefficient_timers.rs
new file mode 100644
index 00000000000..6f3774d3dca
--- /dev/null
+++ b/components/script/horribly_inefficient_timers.rs
@@ -0,0 +1,31 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/// A quick hack to work around the removal of [`std::old_io::timer::Timer`](
+/// http://doc.rust-lang.org/1.0.0-beta/std/old_io/timer/struct.Timer.html )
+
+use std::sync::mpsc::{channel, Receiver};
+use std::thread::{spawn, sleep_ms};
+
+pub fn oneshot(duration_ms: u32) -> Receiver<()> {
+ let (tx, rx) = channel();
+ spawn(move || {
+ sleep_ms(duration_ms);
+ let _ = tx.send(());
+ });
+ rx
+}
+
+pub fn periodic(duration_ms: u32) -> Receiver<()> {
+ let (tx, rx) = channel();
+ spawn(move || {
+ loop {
+ sleep_ms(duration_ms);
+ if tx.send(()).is_err() {
+ break
+ }
+ }
+ });
+ rx
+}