Skip to content

Commit

Permalink
Fix for rust Duration reform (rust-lang/rust#24920)
Browse files Browse the repository at this point in the history
  • Loading branch information
zmbush committed May 18, 2015
1 parent 9e5ccf8 commit 8f84c64
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion prompt_buffer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
unused
)]

#![feature(std_misc)]
#![feature(std_misc, duration)]

extern crate term;

Expand Down
7 changes: 4 additions & 3 deletions prompt_buffer/src/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ fn oneshot_timer(dur: Duration) -> Receiver<()> {
let (tx, rx) = mpsc::channel();

thread::spawn(move || {
thread::sleep_ms(dur.num_milliseconds() as u32);
let time = dur.secs() * 1000 + dur.extra_nanos() as u64 / 1000;
thread::sleep_ms(time as u32);

tx.send(()).unwrap();
});
Expand All @@ -48,7 +49,7 @@ impl PromptThread {
prompt.set_path(p);

loop {
let timeout = oneshot_timer(Duration::minutes(10));
let timeout = oneshot_timer(Duration::from_secs(10*60));

select! {
_ = rx_notify.recv() => {
Expand Down Expand Up @@ -99,7 +100,7 @@ impl PromptThread {

self.send.send(()).unwrap();

let timeout = oneshot_timer(Duration::milliseconds(100));
let timeout = oneshot_timer(Duration::from_millis(100));

loop {
let resp = self.recv.try_recv();
Expand Down
10 changes: 6 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
path_ext,
std_misc,
metadata_ext,
path_relative_from
path_relative_from,
duration
)]

extern crate term;
Expand Down Expand Up @@ -154,8 +155,9 @@ fn do_daemon(socket_path: &Path) {
fn oneshot_timer(dur: Duration) -> Receiver<()> {
let (tx, rx) = mpsc::channel();

let _ = thread::spawn(move || {
thread::sleep_ms(dur.num_milliseconds() as u32);
thread::spawn(move || {
let time = dur.secs() * 1000 + dur.extra_nanos() as u64 / 1000;
thread::sleep_ms(time as u32);

tx.send(()).unwrap();
});
Expand Down Expand Up @@ -230,7 +232,7 @@ fn do_main(socket_path: &Path) {
write!(&mut stream, "{}", env::current_dir().unwrap().display()).unwrap();
stream.shutdown(Shutdown::Write).unwrap();

match read_with_timeout(stream, Duration::milliseconds(200)) {
match read_with_timeout(stream, Duration::from_millis(200)) {
Ok(s) => println!("{}", s),
Err(_) => {
println!("Response too slow");
Expand Down

0 comments on commit 8f84c64

Please sign in to comment.