// cbguard by Shimon Doodkin - license: public domainfunction cbguard(cb,printerr){ //kind of filter for callbacks. it prevents a callback to be called twicevar cb1=cb;return function() {if(cb1) { var cb2=cb1; cb1=false; return cb2.apply(this,arguments); }else if(printerr)console.log(new Error('cb called twice').stack);}}// usage example://function myfunction(cb)//{// cb=cbguard(cb); // usage example// // or// // cb=cbguard(cb,true); // good when developing, it will protect and also tell you you have a problem, here a callback is called twice here.//// things that are based on event emitteres are usually have problems with multiple callbacks.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/0bfddd86-2dfd-4e35-a3a4-72c323e739b7%40googlegroups.com.--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
How do people stumble upon this kind of error?