joyent/node — pull request #3646 by skidding (2012-07-05 20:24:55+00:00)
Title: Domain binding on defining event listeners

Premise: Domains work best only in a synchronous flow. To cover async situations, though, timers bind current domain to their callbacks and event emitters store it in their constructor. (maybe other stuff as well...)

Problem: Async callbacks returned from low-level libraries, like in the case of net streams, are not covered. If the event emitter was not defined inside a certain domain, nor will listeners added to it get bound to any present domain.

Solution: Binding domains on adding event listeners and activating them on emit. (similar to how intervals handle domains)