Skip to content

Commit

Permalink
fix(ios): add semaphore to make sure scope is created
Browse files Browse the repository at this point in the history
  • Loading branch information
ozonelmy authored and zealotchen0 committed Jul 25, 2023
1 parent 74f2d5a commit f27c513
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion framework/ios/base/executors/HippyJSExecutor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ - (void)setup {
auto engine = [[HippyJSEnginesMapper defaultInstance] createJSEngineResourceForKey:self.enginekey];
const char *pName = [self.enginekey UTF8String] ?: "";
auto scope = engine->GetEngine()->CreateScope(pName);
dispatch_semaphore_t scopeSemaphore = dispatch_semaphore_create(0);
__weak HippyJSExecutor *weakSelf = self;
engine->GetEngine()->GetJsTaskRunner()->PostTask([weakSelf](){
engine->GetEngine()->GetJsTaskRunner()->PostTask([weakSelf, scopeSemaphore](){
@autoreleasepool {
HippyJSExecutor *strongSelf = weakSelf;
if (!strongSelf) {
Expand All @@ -117,6 +118,7 @@ - (void)setup {
if (!bridge) {
return;
}
dispatch_semaphore_wait(scopeSemaphore, DISPATCH_TIME_FOREVER);
auto scope = strongSelf->_pScope;
scope->CreateContext();
auto context = scope->GetContext();
Expand Down Expand Up @@ -217,6 +219,7 @@ - (void)setup {
}
});
self.pScope = scope;
dispatch_semaphore_signal(scopeSemaphore);
#ifdef ENABLE_INSPECTOR
HippyBridge *bridge = self.bridge;
if (bridge && bridge.debugMode) {
Expand Down

0 comments on commit f27c513

Please sign in to comment.