Awhile is an adverb meaning for a while, and it only works where it would bear replacement with that three-word phrase. Where for a while wouldn’t work in its place, it is probably not an adverb, so it should be two words: a while.
For instance, in the sentence, “Guests waited awhile for food,” awhile is one word because it is an adverb modifying the verb waited (note also that for a while would work in its place). In the sentences, “We have a while left to wait,” and, “I saw her a while ago,” a while is two words because while functions as a noun.
Awhile has existed in various spellings since the days of Old English,1 but there is a mistaken belief among some English speakers that the word is a new form and thus questionable. That’s why it is so often unnecessarily rendered as two words. And in fact, if you are not comfortable with the word and are unsure if you’re using it correctly, making it two words is always safe because no one will consider it wrong. But careful writers who understand where to deploy the adverbial awhile need not fear it.
But if they give him The Tonight Show back, maybe it ends up all right after a while. [Hollywood.com]
Starlings foray across the land and rest awhile on the sunlit twigs of ash. [Guardian]
After a while, Rawls came in to let another set of children have a chance. [Washington Post]
Crazy Horse watched this awhile and then rode down the river where some men were going out to repair the talking wires. [Crazy Horse: The Strange Man of the Oglalas]
We’ve been talking for a while when Baroness Campbell of Surbiton suddenly cuts to the chase, and leaves me speechless. [Telegraph]
Beyond the bar, soft white leather booths beckon you to sit, take off your coat and stay awhile. [In Arkansas]