Fixed potential stalling of _fireTasksFlushEvents

Task could be put in the flush queue and then embedded before being flushed, causing _fireTasksFlushEvents to stall. This commit fixes that.