Skip to content

Commit

Permalink
fix: Fix race condition crash on iOS (#92)
Browse files Browse the repository at this point in the history
* Retry to set up the library 10ms later

* Update Mmkv.mm
  • Loading branch information
mrousavy authored Jul 8, 2021
1 parent c15c230 commit 522634c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ios/Mmkv.mm
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,28 @@ static void install(jsi::Runtime & jsiRuntime)
jsiRuntime.global().setProperty(jsiRuntime, "mmkvClearAll", std::move(mmkvClearAll));
}

- (void)setBridge:(RCTBridge *)bridge
- (void)setup
{
_bridge = bridge;
_setBridgeOnMainQueue = RCTIsMainQueue();

RCTCxxBridge *cxxBridge = (RCTCxxBridge *)self.bridge;
if (!cxxBridge.runtime) {
// retry 10ms later - THIS IS A WACK WORKAROUND. wait for TurboModules to land.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.001 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self setup];
});
return;
}

[MMKV initializeMMKV:nil];
install(*(jsi::Runtime *)cxxBridge.runtime);
}

- (void)setBridge:(RCTBridge *)bridge
{
_bridge = bridge;
_setBridgeOnMainQueue = RCTIsMainQueue();
[self setup];
}

- (void)invalidate {
[MMKV.defaultMMKV close];
}
Expand Down

0 comments on commit 522634c

Please sign in to comment.