Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
dns: lazy loaded
  • Loading branch information
BridgeAR committed May 14, 2018
commit 02c3b4b154e053a262e6fc16083c76089930293c
9 changes: 6 additions & 3 deletions lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const {
ERR_SOCKET_DGRAM_NOT_RUNNING
} = errors.codes;
const { Buffer } = require('buffer');
const dns = require('dns');
const util = require('util');
const { isUint8Array } = require('internal/util/types');
const EventEmitter = require('events');
Expand All @@ -47,6 +46,9 @@ const { UV_UDP_REUSEADDR } = process.binding('constants').os;

const { UDP, SendWrap } = process.binding('udp_wrap');

// Lazy load for startup performance.
let dns;

const BIND_STATE_UNBOUND = 0;
const BIND_STATE_BINDING = 1;
const BIND_STATE_BOUND = 2;
Expand All @@ -72,9 +74,10 @@ function lookup6(lookup, address, callback) {


function newHandle(type, lookup) {
if (lookup === undefined)
if (lookup === undefined) {
if (dns === undefined) dns = require('dns');
lookup = dns.lookup;
else if (typeof lookup !== 'function')
} else if (typeof lookup !== 'function')
throw new ERR_INVALID_ARG_TYPE('lookup', 'Function', lookup);

if (type === 'udp4') {
Expand Down