@@ -696,7 +696,11 @@ export const createServer = async (
696
696
return e ;
697
697
} ;
698
698
699
- async function waitForPort ( port : number , host = "0.0.0.0" , timeout = 5000 ) : Promise < void > {
699
+ async function waitForPort (
700
+ port : number ,
701
+ host = "0.0.0.0" ,
702
+ timeout = 5000 ,
703
+ ) : Promise < void > {
700
704
const start = Date . now ( ) ;
701
705
while ( Date . now ( ) - start < timeout ) {
702
706
const available = await isPortAvailable ( port , host ) ;
@@ -705,20 +709,23 @@ async function waitForPort(port: number, host = "0.0.0.0", timeout = 5000): Prom
705
709
}
706
710
await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) ) ; // Wait 1 second before retrying
707
711
}
708
- throw new Error ( `Timeout: port ${ port } is still in use after ${ timeout / 1000 } seconds.` ) ;
712
+ throw new Error (
713
+ `Timeout: port ${ port } is still in use after ${ timeout / 1000 } seconds.` ,
714
+ ) ;
709
715
}
710
716
711
717
function isPortAvailable ( port : number , host = "0.0.0.0" ) : Promise < boolean > {
712
718
return new Promise ( ( resolve ) => {
713
- const probe = net . createServer ( )
714
- . once ( 'error' , ( err : NodeJS . ErrnoException ) => {
715
- if ( err . code === 'EADDRINUSE' ) {
719
+ const probe = net
720
+ . createServer ( )
721
+ . once ( "error" , ( err : NodeJS . ErrnoException ) => {
722
+ if ( err . code === "EADDRINUSE" ) {
716
723
resolve ( false ) ; // port is in use
717
724
} else {
718
725
resolve ( false ) ; // some other error occurred
719
726
}
720
727
} )
721
- . once ( ' listening' , ( ) => {
728
+ . once ( " listening" , ( ) => {
722
729
probe . close ( ) ;
723
730
resolve ( true ) ; // port is available
724
731
} )
0 commit comments