Refactor worker event emission code to be less repetitive