It should set it immediately (synchronously), because that's what should happen for the user. That is, the user types something and immediately the loading icon appears (and maybe a few milliseconds later, the ajax request is sent). Does that sound good?