I was using the code for some export and import and stumbled on an error 'Premature end of stream' while importing a previously exported file. The reason was that my exported file did not had endDatabase at the end. It was caused because the last write did not finish and callback was returned before that, because of setImmediate. I worked around that by adding a last empty write on the stream with a callback, which solved the issue. My question is there a reason for using setImmediate instead of the stream.write's callback ?
I was using the code for some export and import and stumbled on an error 'Premature end of stream' while importing a previously exported file. The reason was that my exported file did not had endDatabase at the end. It was caused because the last write did not finish and callback was returned before that, because of setImmediate. I worked around that by adding a last empty write on the stream with a callback, which solved the issue. My question is there a reason for using setImmediate instead of the stream.write's callback ?