File tree Expand file tree Collapse file tree 1 file changed +1
-3
lines changed Expand file tree Collapse file tree 1 file changed +1
-3
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,6 @@ const queue = new BlockingQueue({ concurrency: 2 });
50
50
let handled = 0 ;
51
51
let failed = 0 ;
52
52
let awaitDrain: Promise <void > | undefined ;
53
- let realCount = 0 ;
54
53
55
54
const readStream = fs .createReadStream (' ./users.json' , { flags: ' r' , encoding: ' utf-8' });
56
55
const jsonReadStream = JSONStream .parse (' *' );
@@ -81,7 +80,6 @@ const handleUser = async (user) => {
81
80
await awaitDrain ;
82
81
awaitDrain = undefined ;
83
82
}
84
- realCount ++ ;
85
83
return queue .enqueue (addUserToDB , user ).enqueuePromise ;
86
84
};
87
85
@@ -99,7 +97,7 @@ const mapper = (user, cb) => {
99
97
const onReadEnd = () => {
100
98
console .log (' done read streaming' );
101
99
// If nothing was written, idle event will not be fired
102
- if (realCount === 0 ) {
100
+ if (queue . pendingCount === 0 && queue . activeCount === 0 ) {
103
101
jsonWriteStream .end ();
104
102
} else {
105
103
// Wait until all work is done
You can’t perform that action at this time.
0 commit comments