Is this modern #Swift

@libei Not sure if it matters here, but there’s no guarantee for /when/ the body of the loop will be called.

Imagine wrapping everything in DispatchQueue.main.async {} <- you may have subtle UI issues if you’re reacting to notifications async from the context where they were posted.

(Maybe in this case it’s fine?!)

@edwellbrook setUpNotificationTask() is implicitly protected by MainActor, so the Task will inherit MainActor and (I assume) the body of loops will be executed on MainActor/thread.

But I don't 100% sure about how notifications(named:) works, so perhaps I'm already in a situation, like DispatchQueue.main.async {}, reacting to notifications asynchronously.  

Honestly Swift Concurrency is really painful. 😇

@libei Yes, this is all executed on the main actor (the “where”), but because there’s a Task + await, there’s no guaruntee on the “when”. So treat this like main.async {}.

If you care about reacting to the notif “inline” from where it was posted, you probably want to use the addObserver method. You may/may not need to care about that here!

@edwellbrook Guess we have to use the old good target action way.  

https://mastodon.social/@libei/112094098430886878

@libei 🥲🥲