priore

Threads Helper

Feb 27th, 2017
636
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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×