mirror of https://github.com/oxen-io/session-ios
Register all database views asynchronously.
parent
96b7dc5163
commit
5cf89a0f3d
@ -0,0 +1,21 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
typedef void (^AppReadyBlock)(void);
|
||||
|
||||
@interface AppReadiness : NSObject
|
||||
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
|
||||
+ (BOOL)isAppReady;
|
||||
|
||||
+ (void)setAppIsReady;
|
||||
|
||||
+ (void)runNowOrWhenAppIsReady:(AppReadyBlock)block;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@ -0,0 +1,100 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "AppReadiness.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface AppReadiness ()
|
||||
|
||||
@property (atomic) BOOL isAppReady;
|
||||
|
||||
@property (nonatomic, nullable) NSMutableArray<AppReadyBlock> *appReadyBlocks;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@implementation AppReadiness
|
||||
|
||||
+ (instancetype)sharedManager
|
||||
{
|
||||
static AppReadiness *sharedMyManager = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
sharedMyManager = [[self alloc] initDefault];
|
||||
});
|
||||
return sharedMyManager;
|
||||
}
|
||||
|
||||
- (instancetype)initDefault
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
OWSSingletonAssert();
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (BOOL)isAppReady
|
||||
{
|
||||
return self.sharedManager.isAppReady;
|
||||
}
|
||||
|
||||
+ (void)runNowOrWhenAppIsReady:(AppReadyBlock)block
|
||||
{
|
||||
OWSAssertIsOnMainThread();
|
||||
|
||||
[self.sharedManager runNowOrWhenAppIsReady:block];
|
||||
}
|
||||
|
||||
- (void)runNowOrWhenAppIsReady:(AppReadyBlock)block
|
||||
{
|
||||
OWSAssertIsOnMainThread();
|
||||
OWSAssert(block);
|
||||
|
||||
if (self.isAppReady) {
|
||||
block();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!self.appReadyBlocks) {
|
||||
self.appReadyBlocks = [NSMutableArray new];
|
||||
}
|
||||
[self.appReadyBlocks addObject:block];
|
||||
}
|
||||
|
||||
+ (void)setAppIsReady
|
||||
{
|
||||
[self.sharedManager setAppIsReady];
|
||||
}
|
||||
|
||||
- (void)setAppIsReady
|
||||
{
|
||||
OWSAssertIsOnMainThread();
|
||||
OWSAssert(!self.isAppReady);
|
||||
|
||||
self.isAppReady = YES;
|
||||
|
||||
[self runAppReadyBlocks];
|
||||
}
|
||||
|
||||
- (void)runAppReadyBlocks
|
||||
{
|
||||
OWSAssertIsOnMainThread();
|
||||
OWSAssert(self.isAppReady);
|
||||
|
||||
for (AppReadyBlock block in self.appReadyBlocks) {
|
||||
block();
|
||||
}
|
||||
self.appReadyBlocks = nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
Loading…
Reference in New Issue