Icard/angular-clarity-master(work.../node_modules/karma/lib/utils/net-utils.js

28 lines
647 B
JavaScript
Raw Permalink Normal View History

2024-07-16 14:55:36 +00:00
'use strict'
const net = require('net')
const NetUtils = {
bindAvailablePort (port, listenAddress) {
return new Promise((resolve, reject) => {
const server = net.createServer()
server
.on('error', (err) => {
server.close()
if (err.code === 'EADDRINUSE' || err.code === 'EACCES') {
server.listen(++port, listenAddress)
} else {
reject(new Error(`Failed to bind ${port}: ` + (err.stack || err)))
}
})
.on('listening', () => {
resolve(server)
})
.listen(port, listenAddress)
})
}
}
module.exports = NetUtils