This needs a comment as to what this function is for - i.e. handling long polling events if I'm understanding correctly. It isn't obvious from a glance.