0
假设customWS
是写流..实现自定义写流类的完成事件处理
util.inherits(customWS, stream.Writable);
我们实现我们的逻辑来处理在_write()
像下面的写..
customWS.prototype._write = function(chunk, encoding, done) {
// ...
}
现在要使用customWS
类,我们会做类似下面的操作。
aReadableStream.pipe(new customWS()).on('finish', callback);
那么callback
函数的参数是什么?
我可以通过一个像callback
..
function(data) {
// ...
}
..或它固定??
如果它不是固定的,那么如何在customWS
类中实现这样的回调?
有类似的东西..
// in the implementation of customWS class
customWS.prototype._finish = function(user_specified_callback) {
user_specified_callback(some_data_say_a_bool_val);
}
// in the code, where i use the customWS class
aReadableStream.pipe(new customWS()).on('finish', function(flag) {
if (flag) {
console.log('yes');
}
});