diff --git a/framework/ios/base/executors/HippyJSExecutor.mm b/framework/ios/base/executors/HippyJSExecutor.mm index beb4e42e096..bf289863925 100644 --- a/framework/ios/base/executors/HippyJSExecutor.mm +++ b/framework/ios/base/executors/HippyJSExecutor.mm @@ -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) { @@ -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(); @@ -217,6 +219,7 @@ - (void)setup { } }); self.pScope = scope; + dispatch_semaphore_signal(scopeSemaphore); #ifdef ENABLE_INSPECTOR HippyBridge *bridge = self.bridge; if (bridge && bridge.debugMode) {