IntrepidPursuits / swift-wisdom

A collection of additions to the Swift Standard Library created by Intrepid Pursuits developers
MIT License
39 stars 14 forks source link

Check if already on main thread #149

Closed MaxHasADHD closed 6 years ago

MaxHasADHD commented 6 years ago

Don't need to dispatch async if already on the main thread.

ghost commented 6 years ago
1 Message
:book: Executed 169 tests, with 0 failures (0 unexpected) in 0.467 (0.544) seconds

Generated by :no_entry_sign: Danger

bobgilmore commented 6 years ago

I'm not behind this change. If someone is on the main thread already, the current implementation of Main will (I believe) enqueue the function call onto the end of the main thread. That would defer execution of function until some future run through the event queue. This may well be what the caller intended. It's what I've always assumed.

This change would break that behavior, resulting in function being executed immediately and synchronously.

If the caller wants this kind of conditional behavior, I think they should perform the check at the call site. If we really want to provide this behavior in a library call, I advocate for another method, or (at least) have an optional boolean parameter on this method to specify the behavior.