Tag: streamstream

为什么在完成之前,“完成”事件在Node.js转换stream上触发?

我期待只有当传递给_flush的callback完成后才能触发callback,但是在_flush完成之前触发callback。 为什么? var stream = require('stream').Transform(); // Nothing interesting here stream._transform = function (chunk, enc, next) { next(); }; // _flush makes an async call. stream._flush = function (callback) { console.log("Expecting 1st: Entering _flush "); return process.nextTick(function () { console.log("Expecting 2nd: Done with _flush"); callback(); }); }; stream.on('finish',function () { console.log("Expecting 3rd: Entering finish callback– […]