File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed
Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import * as dbus from 'dbus-next';
55import * as events from 'events' ;
66
77import * as dnssd from '../dnssd' ;
8+ import { time } from 'console' ;
89
910const PROTO_INET = 0 ;
1011const PROTO_INET6 = 1 ;
@@ -56,13 +57,15 @@ async function getServer(): Promise<Server> {
5657 // dbus-next will queue messages and wait forever for a connection
5758 // so we have to hack in a timeout, otherwise we end up with a deadlock
5859 // on systems without D-Bus.
59- await new Promise ( ( resolve , reject ) => setTimeout ( ( ) => {
60- if ( ( bus as any ) . _connection . state === 'connected' ) {
61- resolve ( ) ;
62- } else {
60+ await new Promise ( ( resolve , reject ) => {
61+ const timeout = setTimeout ( ( ) => {
6362 reject ( Error ( "Timeout while connecting to D-Bus" ) ) ;
64- }
65- } , 100 ) ) ;
63+ } , 100 ) ;
64+ ( bus as any ) . on ( 'connect' , ( ) => {
65+ clearTimeout ( timeout ) ;
66+ resolve ( ) ;
67+ } ) ;
68+ } ) ;
6669 const proxy = await bus . getProxyObject ( 'org.freedesktop.Avahi' , '/' ) ;
6770 const server = proxy . getInterface < Server > ( 'org.freedesktop.Avahi.Server' ) ;
6871 const version = await server . GetAPIVersion ( ) ;
You can’t perform that action at this time.
0 commit comments