Skip to content

Commit 60eab91

Browse files
BridgeARMylesBorins
authored andcommitted
dns: lazy loaded
PR-URL: #20567 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
1 parent 28d00a1 commit 60eab91

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎lib/dgram.js‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const {
3535
ERR_SOCKET_DGRAM_NOT_RUNNING
3636
}=errors.codes;
3737
const{ Buffer }=require('buffer');
38-
constdns=require('dns');
3938
constutil=require('util');
4039
const{ isUint8Array }=require('internal/util/types');
4140
constEventEmitter=require('events');
@@ -47,6 +46,9 @@ const { UV_UDP_REUSEADDR } = process.binding('constants').os;
4746

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

49+
// Lazy load for startup performance.
50+
letdns;
51+
5052
constBIND_STATE_UNBOUND=0;
5153
constBIND_STATE_BINDING=1;
5254
constBIND_STATE_BOUND=2;
@@ -72,9 +74,10 @@ function lookup6(lookup, address, callback) {
7274

7375

7476
functionnewHandle(type,lookup){
75-
if(lookup===undefined)
77+
if(lookup===undefined){
78+
if(dns===undefined)dns=require('dns');
7679
lookup=dns.lookup;
77-
elseif(typeoflookup!=='function')
80+
}elseif(typeoflookup!=='function')
7881
thrownewERR_INVALID_ARG_TYPE('lookup','Function',lookup);
7982

8083
if(type==='udp4'){

0 commit comments

Comments
 (0)