feat:avoid iOS dealloc JSValue in main thread,this may cause crash in JavaScriptCore

This commit is contained in:
pengfeizhou
2021-01-06 11:56:30 +08:00
committed by osborn
parent 967ad27a22
commit 2100eff054
7 changed files with 29 additions and 8 deletions

View File

@@ -89,4 +89,19 @@ - (id)waitUntilResult {
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
return self.result;
}
- (id)waitUntilResult:(id (^)(id result))transformer {
if (self.result) {
return transformer(self.result);
}
__block id ret = nil;
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
self.resultCallback = ^(id r) {
ret = transformer(r);
dispatch_semaphore_signal(semaphore);
};
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
return ret;
}
@end