feat:avoid iOS dealloc JSValue in main thread,this may cause crash in JavaScriptCore
This commit is contained in:
@@ -24,7 +24,6 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
|
||||
@interface DoricAsyncResult <R> : NSObject
|
||||
@property(nonatomic, strong) void (^resultCallback)(R result);
|
||||
@property(nonatomic, strong) void (^exceptionCallback)(NSException *e);
|
||||
@@ -39,6 +38,9 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
- (R)getResult;
|
||||
|
||||
- (R)waitUntilResult;
|
||||
|
||||
- (id)waitUntilResult:(id (^)(R result))transformer;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user