session-ios/SignalServiceKit/src/Util/Threading.m
Michael Kirk 5c432a2bc1 Fix crash on launch in debug.
OWSReadReceiptManager is not `init` on the main thread; however, because
it "schedules" it's own processing during init.

I considered dispatching to main, but since AppReadiness already *can*
resolve async if the app isn't yet ready, it should be no less safe to
also dispatch async when it's off the main thread.

// FREEBIE
2018-02-14 13:47:45 -08:00

36 lines
622 B
Objective-C

//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "Threading.h"
NS_ASSUME_NONNULL_BEGIN
void DispatchMainThreadSafe(dispatch_block_t block)
{
OWSCAssert(block);
if ([NSThread isMainThread]) {
block();
} else {
dispatch_async(dispatch_get_main_queue(), ^{
block();
});
}
}
void DispatchSyncMainThreadSafe(dispatch_block_t block)
{
OWSCAssert(block);
if ([NSThread isMainThread]) {
block();
} else {
dispatch_sync(dispatch_get_main_queue(), ^{
block();
});
}
}
NS_ASSUME_NONNULL_END