Set state before emitting signal to mitigate a race condition.