AsyncEventSource: added waitConnectionState(int) and handling of connection state to the MessageLoop