Chapter 04 - Prepending `await` to NotificationCenter.Default.notifications(for:)

Hello there,

I’m wondering why I should prepend await keyword to NotificationCenter.default.notifications(for:) method which is introduced in Adding an asynchronous stream to NotificationCenter section. :thinking: notifications(for:) only returns AsyncStream and it doesn’t seem to await something.

But if I omit await keyword, the compiler complains that “Expression is ‘async’ but is not marked with ‘await’”. The error goes away if I remove async keyword from the method observeAppStatus() which calls notifications(for:) method.

I really appreciate if you could explain the reason prepending await keyword to notifications(for:) method.

Best regards,

Henry.

Hi Henry, this question has come up previously over here: Await for loop in book chapter4. Looks like it might be a good idea to add a note in the text to avoid confusion :slight_smile:

1 Like