attemptStartUntilPortAvailable

fun attemptStartUntilPortAvailable(startingPort: Int, onReady: (Stoppable, port: Int) -> Unit)

Attempts to start the server on a free port. Only a port reported as occupied before onReady starts makes the scan advance: any other failure propagates to the caller instead of being retried on another port.

Parameters

startingPort

port to start from

onReady

callback called when the server is ready to accept requests, with the application and port as arguments. It is invoked at most once, no matter how many ports the scan goes through

Throws

IOException

if no port in the startingPort..65535 range is available