Skip to content

Commit 3a0cf5b

Browse files
committed
DRY up listenerCount check
1 parent dcfc8b8 commit 3a0cf5b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/sink.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ function listenerCount(stream, evt) {
66
return stream.listeners(evt).length;
77
}
88

9+
function hasListeners(stream) {
10+
return !!(listenerCount(stream, 'readable') || listenerCount(stream, 'data'));
11+
}
12+
913
function sink(stream) {
1014
var sinkStream = new Writable({
1115
objectMode: true,
@@ -19,7 +23,7 @@ function sink(stream) {
1923
return;
2024
}
2125

22-
if (listenerCount(stream, 'readable') || listenerCount(stream, 'data')) {
26+
if (hasListeners(stream)) {
2327
stream.unpipe(sinkStream);
2428
}
2529
}
@@ -28,7 +32,7 @@ function sink(stream) {
2832
stream.on('removeListener', removeSink);
2933

3034
return function() {
31-
if (listenerCount(stream, 'readable') || listenerCount(stream, 'data')) {
35+
if (hasListeners(stream)) {
3236
return;
3337
}
3438

0 commit comments

Comments
 (0)