1 | module.exports = promisify
|
2 |
|
3 | function promisify (fn, args) {
|
4 | if (typeof Promise === 'undefined') {
|
5 | throw new Error('Please run in a Promise supported environment or provide a callback')
|
6 | }
|
7 | return new Promise(function (resolve, reject) {
|
8 | args = [].slice.call(args).concat([callback])
|
9 | fn.apply(null, args)
|
10 |
|
11 | function callback (error, port) {
|
12 | if (error || port === false) {
|
13 | reject(error || new Error('No open port found'))
|
14 | } else {
|
15 | resolve(port)
|
16 | }
|
17 | }
|
18 | })
|
19 | }
|