You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
511 B

6 years ago
module.exports = promisify
function promisify (fn, args) {
if (typeof Promise === 'undefined') {
throw new Error('Please run in a Promise supported environment or provide a callback')
}
return new Promise(function (resolve, reject) {
args = [].slice.call(args).concat([callback])
fn.apply(null, args)
function callback (error, port) {
if (error || port === false) {
reject(error || new Error('No open port found'))
} else {
resolve(port)
}
}
})
}