sockjs/sockjs-client — pull request #127 by davidben (2013-07-02 05:50:54+00:00)
Title: Fix handling of listeners added and removed mid-dispatch

Before, having the last event listener remove itself (to implement
EventEmitter.prototype.once-like semantics) threw an exception. Fix this by
making a copy of the listener list on dispatch. While we're at it, mimic the
semantics of the real DOM EventTarget interface. Event listeners added
mid-dispatch do not run until the next one, however listeners removed, if they
have not yet run, will not run in the current one.

Also adds a unit test to test this behavior.