Skip to content

Commit 8f84c64

Browse files
committed
Fix for rust Duration reform (rust-lang/rust#24920)
1 parent 9e5ccf8 commit 8f84c64

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

prompt_buffer/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
unused
1616
)]
1717

18-
#![feature(std_misc)]
18+
#![feature(std_misc, duration)]
1919

2020
extern crate term;
2121

prompt_buffer/src/thread.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ fn oneshot_timer(dur: Duration) -> Receiver<()> {
2626
let (tx, rx) = mpsc::channel();
2727

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

3132
tx.send(()).unwrap();
3233
});
@@ -48,7 +49,7 @@ impl PromptThread {
4849
prompt.set_path(p);
4950

5051
loop {
51-
let timeout = oneshot_timer(Duration::minutes(10));
52+
let timeout = oneshot_timer(Duration::from_secs(10*60));
5253

5354
select! {
5455
_ = rx_notify.recv() => {
@@ -99,7 +100,7 @@ impl PromptThread {
99100

100101
self.send.send(()).unwrap();
101102

102-
let timeout = oneshot_timer(Duration::milliseconds(100));
103+
let timeout = oneshot_timer(Duration::from_millis(100));
103104

104105
loop {
105106
let resp = self.recv.try_recv();

src/main.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
path_ext,
1515
std_misc,
1616
metadata_ext,
17-
path_relative_from
17+
path_relative_from,
18+
duration
1819
)]
1920

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

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

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

233-
match read_with_timeout(stream, Duration::milliseconds(200)) {
235+
match read_with_timeout(stream, Duration::from_millis(200)) {
234236
Ok(s) => println!("{}", s),
235237
Err(_) => {
236238
println!("Response too slow");

0 commit comments

Comments
 (0)