@@ -237,21 +237,23 @@ - (void)fetchABTestWithModeType:(SABFetchABTestModeType)type paramName:(NSString
237237 return ;
238238 }
239239 if (![SABValidUtils isValidString: paramName]) {
240- dispatch_async ( dispatch_get_main_queue (), ^ {
240+ if (type == SABFetchABTestModeTypeCache) {
241241 completionHandler (defaultValue);
242- });
242+ } else {
243+ // fast 和 async 异步接口,统一主线程回调结果
244+ dispatch_async (dispatch_get_main_queue (), ^{
245+ completionHandler (defaultValue);
246+ });
247+ }
243248 SABLogError (@" paramName: %@ error,paramName must be a valid string!" , paramName);
244249 return ;
245250 }
246-
251+
247252 switch (type) {
248253 case SABFetchABTestModeTypeCache: {
249254 // 从缓存读取
250255 id cacheValue = [self fetchCacheABTestWithParamName: paramName defaultValue: defaultValue];
251- dispatch_async (dispatch_get_main_queue (), ^{
252- completionHandler (cacheValue ? : defaultValue);
253- });
254- return ;
256+ return completionHandler (cacheValue ? : defaultValue);
255257 }
256258 case SABFetchABTestModeTypeFast: {
257259 id cacheValue = [self fetchCacheABTestWithParamName: paramName defaultValue: defaultValue];
@@ -267,8 +269,8 @@ - (void)fetchABTestWithModeType:(SABFetchABTestModeType)type paramName:(NSString
267269 case SABFetchABTestModeTypeAsync: {
268270 // 异步请求
269271 [self fetchAsyncABTestWithParamName: paramName defaultValue: defaultValue timeoutInterval: timeoutInterval completionHandler: completionHandler];
272+ break ;
270273 }
271- break ;
272274 default :
273275 break ;
274276 }
@@ -306,23 +308,23 @@ - (void)fetchAsyncABTestWithParamName:(NSString *)paramName defaultValue:(id)def
306308 // 异步请求
307309 SABExperimentRequest *requestData = [[SABExperimentRequest alloc ] initWithBaseURL: self .configOptions.baseURL projectKey: self .configOptions.projectKey];
308310 requestData.timeoutInterval = timeoutInterval;
309-
311+
310312 __weak typeof (self) weakSelf = self;
311313 [self .dataManager asyncFetchAllExperimentWithRequest: requestData completionHandler: ^(SABFetchResultResponse *_Nullable responseData, NSError *_Nullable error) {
312314 __strong typeof (weakSelf) strongSelf = weakSelf;
313-
315+
314316 if (error || !responseData) {
315317 SABLogError (@" asyncFetchAllExperimentWithRequest failure,error: %@ " , error);
316- // 切到主线程回调结果
318+ // 请求失败,主线程回调结果
317319 dispatch_async (dispatch_get_main_queue (), ^{
318320 completionHandler (defaultValue);
319321 });
320322 return ;
321323 }
322-
324+
323325 // 获取缓存并触发 $ABTestTrigger 事件
324326 id cacheValue = [strongSelf fetchCacheABTestWithParamName: paramName defaultValue: defaultValue];
325-
327+
326328 // 切到主线程回调结果
327329 dispatch_async (dispatch_get_main_queue (), ^{
328330 completionHandler (cacheValue ? : defaultValue);
0 commit comments