SHARE
TWEET

Threads Helper

priore Feb 27th, 2017 (edited) 467 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. NS_INLINE void OnMainThread(int64_t after_sec, dispatch_block_t block)
  2. {
  3.     if (!block)
  4.         return;
  5.     else if (after_sec > 0)
  6.         dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(after_sec * NSEC_PER_SEC)), dispatch_get_main_queue(), block);
  7.     else if ([NSThread isMainThread])
  8.         block();
  9.     else
  10.         dispatch_async(dispatch_get_main_queue(), block);
  11. }
  12.  
  13. NS_INLINE void OnNewThread(long priority, int64_t after_sec, dispatch_block_t block)
  14. {
  15.     if (!block)
  16.         return;
  17.     else if (after_sec > 0)
  18.         dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(after_sec * NSEC_PER_SEC)), dispatch_get_global_queue(priority, 0), block);
  19.     else if (![NSThread isMainThread])
  20.         block();
  21.     else
  22.         dispatch_async(dispatch_get_global_queue(priority, 0), block);
  23. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top