Flush pending calls off the main-thread

Reviewed By: majak

Differential Revision: D3535193

fbshipit-source-id: 8c4736629eab3c723641f0c3fb449c168cd492a1
This commit is contained in:
Pieter De Baets 2016-07-11 13:15:59 -07:00 committed by Facebook Github Bot 8
parent af7104b49e
commit 2ae23d9f36
1 changed files with 11 additions and 7 deletions

View File

@ -187,11 +187,13 @@ RCT_EXTERN NSArray<Class> *RCTGetModuleClasses(void);
} else {
// Allow testing without a script
dispatch_async(dispatch_get_main_queue(), ^{
[self didFinishLoading];
[[NSNotificationCenter defaultCenter]
postNotificationName:RCTJavaScriptDidLoadNotification
object:self->_parentBridge userInfo:@{@"bridge": self}];
});
[self flushPendingCalls];
onSourceLoad(nil, nil, 0);
}
}
@ -477,14 +479,15 @@ RCT_EXTERN NSArray<Class> *RCTGetModuleClasses(void);
NSRunLoop *targetRunLoop = [self->_javaScriptExecutor isKindOfClass:[RCTJSCExecutor class]] ? [NSRunLoop currentRunLoop] : [NSRunLoop mainRunLoop];
[self->_displayLink addToRunLoop:targetRunLoop];
// Perform the state update and notification on the main thread, so we can't run into
// Perform the notification on the main thread, so we can't run into
// timing issues with RCTRootView
dispatch_async(dispatch_get_main_queue(), ^{
[self didFinishLoading];
[[NSNotificationCenter defaultCenter]
postNotificationName:RCTJavaScriptDidLoadNotification
object:self->_parentBridge userInfo:@{@"bridge": self}];
});
[self flushPendingCalls];
}];
#if RCT_DEV
@ -495,17 +498,18 @@ RCT_EXTERN NSArray<Class> *RCTGetModuleClasses(void);
NSNumber *port = self.bundleURL.port;
[self enqueueJSCall:@"HMRClient.enable" args:@[@"ios", path, host, RCTNullIfNil(port)]];
}
#endif
}
- (void)didFinishLoading
- (void)flushPendingCalls
{
[_performanceLogger markStopForTag:RCTPLBridgeStartup];
_loading = NO;
[_javaScriptExecutor executeBlockOnJavaScriptQueue:^{
for (dispatch_block_t call in self->_pendingCalls) {
_loading = NO;
for (dispatch_block_t call in _pendingCalls) {
call();
}
}];