mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Upgrade to rustc 551a74dddd84cf01440ee84148ebd18bc68bd7c8.
This commit is contained in:
parent
7b87085c18
commit
ef8edd4e87
168 changed files with 2247 additions and 2408 deletions
31
components/script/horribly_inefficient_timers.rs
Normal file
31
components/script/horribly_inefficient_timers.rs
Normal file
|
@ -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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue