making the net module usable only after the ready event.

This commit is contained in:
ali.ibrahim 2016-10-14 17:57:37 +02:00
parent ac9e6eda95
commit 0e13b8dd01

View file

@ -7,6 +7,7 @@ const Readable = require('stream').Readable
const binding = process.atomBinding('net')
const {net, Net} = binding
const {URLRequest} = net
const {app} = require('electron')
Object.setPrototypeOf(Net.prototype, EventEmitter.prototype)
Object.setPrototypeOf(URLRequest.prototype, EventEmitter.prototype)
@ -106,6 +107,10 @@ class ClientRequest extends EventEmitter {
constructor (options, callback) {
super()
if (!app.isReady()) {
throw new Error('net module can only be used after app is ready')
}
if (typeof options === 'string') {
options = url.parse(options)
} else {