duemunk / Async

Syntactic sugar in Swift for asynchronous dispatches in Grand Central Dispatch
MIT License
4.59k stars 316 forks source link

Added option: Async on main thread only if not on main thread #67

Closed mortenholmgaard closed 8 years ago

mortenholmgaard commented 9 years ago

I will suggest to add an option to call a block either sync on main thread if already on main thread, or else async dispatch on the main thread. I have this usecase quite offen.

duemunk commented 9 years ago

It's definitely used in different places. I usually just use Async.main {} so that I'm guaranteed to be on the main thread. Doing it sync if already on main, doesn't give me anything extra, but concerns if code acts different because it changes between being async and sync depending on whether how an API is implemented. IMHO. Also, I don't have any part dispatch_sync in the library yet.

Feel free to start creating a PR with an implementation and use cases for this!