Skip to content

Commit

Permalink
stream: refactor lazyLoadPromises
Browse files Browse the repository at this point in the history
PR-URL: #34354
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Robert Nagy <[email protected]>
Reviewed-By: Zeyu Yang <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
rickyes authored and mcollina committed Jul 17, 2020
1 parent 08e8997 commit 5aeaff6
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,30 @@ Stream.PassThrough = require('_stream_passthrough');
Stream.pipeline = pipeline;
Stream.finished = eos;

function lazyLoadPromises() {
if (promises === null) promises = require('stream/promises');
return promises;
}

ObjectDefineProperty(Stream, 'promises', {
configurable: true,
enumerable: true,
get() {
if (promises === null) promises = require('stream/promises');
return promises;
return lazyLoadPromises();
}
});

ObjectDefineProperty(pipeline, customPromisify, {
enumerable: true,
get() {
if (promises === null) promises = require('stream/promises');
return promises.pipeline;
return lazyLoadPromises().pipeline;
}
});

ObjectDefineProperty(eos, customPromisify, {
enumerable: true,
get() {
if (promises === null) promises = require('stream/promises');
return promises.finished;
return lazyLoadPromises().finished;
}
});

Expand Down

0 comments on commit 5aeaff6

Please sign in to comment.