javascript - Nodeschool's Stream-Adventure #12 Duplexer redux -
it's been days since i'm trying several ways solve exercice. give up. doing wrong here ? why getting "write after end" error if event i'm using "end" event , don't write pipe ? i'm changing object after it's use. or @ least think so.
var duplexer2 = require("duplexer2"); var through = require('through2'); module.exports = function (counter) { var countries = {}; var duplex = duplexer2(through.obj(function (obj, encoding, done) { if (obj.country in countries) countries[obj.country]++; else countries[obj.country] = 1; done(); }), counter); duplex.on("finish", function() { counter.setcounts(countries); }); counter.pipe(duplex); return duplex; };
if substitute line counter.setcounts(countries);
console.log(countries)
see it's populated correctly.
problem text: http://pastebin.com/vam4vkzg
i have read exercice test file , counldn't clue compares objects see if they're correct.
your solution correct. remove counter.pipe(duplex);
line , works. not need pipe duplex stream created, stream adventure going check if works :).
Comments
Post a Comment