File tree Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ impl Drop for Daemon {
73
73
74
74
fn sleep ( ) {
75
75
use std:: { thread, time} ;
76
- let ten_millis = time:: Duration :: from_millis ( 100 ) ;
76
+ let ten_millis = time:: Duration :: from_millis ( 10 ) ;
77
77
thread:: sleep ( ten_millis) ;
78
78
}
79
79
@@ -87,20 +87,27 @@ impl Daemon {
87
87
. arg ( & config. config_path )
88
88
. spawn ( )
89
89
. expect ( "Could not create mpd daemon." ) ;
90
- while !config. sock_path . exists ( ) { }
91
90
92
- // FIXME: Wait for mpd to finish updating the database.
93
- sleep ( ) ;
94
-
95
- Daemon {
91
+ let daemon = Daemon {
96
92
_temp_dir : temp_dir,
97
93
config : config,
98
94
process : process,
95
+ } ;
96
+
97
+ // Wait until we can connect to the daemon
98
+ while let Err ( _) = daemon. maybe_connect ( ) {
99
+ sleep ( )
99
100
}
101
+
102
+ daemon
103
+ }
104
+
105
+ fn maybe_connect ( & self ) -> Result < mpd:: Client < UnixStream > , mpd:: error:: Error > {
106
+ let stream = UnixStream :: connect ( & self . config . sock_path ) ?;
107
+ mpd:: Client :: new ( stream)
100
108
}
101
109
102
110
pub fn connect ( & self ) -> mpd:: Client < UnixStream > {
103
- let stream = UnixStream :: connect ( & self . config . sock_path ) . unwrap ( ) ;
104
- mpd:: Client :: new ( stream) . unwrap ( )
111
+ self . maybe_connect ( ) . expect ( "Could not connect to daemon." )
105
112
}
106
113
}
You can’t perform that action at this time.
0 commit comments