mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
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
36 lines
622 B
Objective-C
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
|