Yes, I hadn't quite thought of that, but it isn't the best solution for what I'm currently trying to achieve: a Node.js-to-native-library module, in that because I'm using a third-party library with subscribe/unsubscribe functions, it would mean I would have to wait until the first data emitted until I could realise that there are no longer any listeners and remove them. In reality there's not much of a difference or performance change as it would only be one time per event per addition/removal cycle, and I doubt people would be removing listeners so much that it needs to be super high performance, but it does feel a bit silly that node core has one event (ie. newListener, which is even used in readline as you say) but not the other - if just for the sake of completeness (as long as it doesn't cause any extra sort of performance hit).
On Saturday, 12 May 2012 04:46:26 UTC+10, Nathan Rajlich wrote: > > On that note, perhaps take inspiration from the "readline" module in > node-core: > https://github.com/joyent/node/blob/a811a4a13042a4b3ba019fbe1221f4c83b02a699/lib/readline.js#L776-804 > > It checks for listeners.length on the 'data' event, and if nobody's > listening then it unregisters the 'data' handler completely. > > On Thu, May 10, 2012 at 7:07 PM, mscdex wrote: > >> I'm curious as to if just checking `foo.listeners('event').length > 0` >> is good enough for your application? >> > >
