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
pull/1/head
Michael Kirk 7 years ago
parent 0522f33a86
commit 5c432a2bc1

@ -3,6 +3,7 @@
// //
#import "AppReadiness.h" #import "AppReadiness.h"
#import "Threading.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -48,9 +49,9 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)runNowOrWhenAppIsReady:(AppReadyBlock)block + (void)runNowOrWhenAppIsReady:(AppReadyBlock)block
{ {
OWSAssertIsOnMainThread(); DispatchMainThreadSafe(^{
[self.sharedManager runNowOrWhenAppIsReady:block]; [self.sharedManager runNowOrWhenAppIsReady:block];
});
} }
- (void)runNowOrWhenAppIsReady:(AppReadyBlock)block - (void)runNowOrWhenAppIsReady:(AppReadyBlock)block

@ -4,16 +4,14 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
typedef void (^SimpleBlock)(void);
// The block is executed immediately if called from the // The block is executed immediately if called from the
// main thread; otherwise it is dispatched async to the // main thread; otherwise it is dispatched async to the
// main thread. // main thread.
void DispatchMainThreadSafe(SimpleBlock block); void DispatchMainThreadSafe(dispatch_block_t block);
// The block is executed immediately if called from the // The block is executed immediately if called from the
// main thread; otherwise it is dispatched sync to the // main thread; otherwise it is dispatched sync to the
// main thread. // main thread.
void DispatchSyncMainThreadSafe(SimpleBlock block); void DispatchSyncMainThreadSafe(dispatch_block_t block);
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -6,7 +6,7 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
void DispatchMainThreadSafe(SimpleBlock block) void DispatchMainThreadSafe(dispatch_block_t block)
{ {
OWSCAssert(block); OWSCAssert(block);
@ -19,7 +19,7 @@ void DispatchMainThreadSafe(SimpleBlock block)
} }
} }
void DispatchSyncMainThreadSafe(SimpleBlock block) void DispatchSyncMainThreadSafe(dispatch_block_t block)
{ {
OWSCAssert(block); OWSCAssert(block);

Loading…
Cancel
Save