File tree Expand file tree Collapse file tree 3 files changed +31
-5
lines changed Expand file tree Collapse file tree 3 files changed +31
-5
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import { OdpConfig } from './odp_config';
2424import { IOdpEventApiManager } from './odp_event_api_manager' ;
2525import { invalidOdpDataFound } from './odp_utils' ;
2626import { IUserAgentParser } from './user_agent_parser' ;
27+ import { scheduleMicrotaskOrTimeout } from '../../utils/microtasks' ;
2728
2829const MAX_RETRIES = 3 ;
2930
@@ -393,14 +394,14 @@ export abstract class OdpEventManager implements IOdpEventManager {
393394
394395 if ( batch . length > 0 ) {
395396 // put sending the event on another event loop
396- queueMicrotask ( async ( ) => {
397+ scheduleMicrotaskOrTimeout ( async ( ) => {
397398 let shouldRetry : boolean ;
398399 let attemptNumber = 0 ;
399400 do {
400401 shouldRetry = await this . apiManager . sendEvents ( odpConfig , batch ) ;
401402 attemptNumber += 1 ;
402403 } while ( shouldRetry && attemptNumber < this . retries ) ;
403- } ) ;
404+ } )
404405 }
405406 }
406407
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import { ERROR_MESSAGES } from '../../utils/enums';
2020import { createOptimizelyConfig } from '../optimizely_config' ;
2121import { OnReadyResult , OptimizelyConfig , DatafileManager } from '../../shared_types' ;
2222import { ProjectConfig , toDatafile , tryCreatingProjectConfig } from '../project_config' ;
23+ import { scheduleMicrotaskOrTimeout } from '../../utils/microtasks' ;
2324
2425const logger = getLogger ( ) ;
2526const MODULE_NAME = 'PROJECT_CONFIG_MANAGER' ;
@@ -189,10 +190,9 @@ export class ProjectConfigManager {
189190 if ( configObj && oldRevision !== configObj . revision ) {
190191 this . configObj = configObj ;
191192 this . optimizelyConfigObj = null ;
192-
193- queueMicrotask ( ( ) => {
193+ scheduleMicrotaskOrTimeout ( ( ) => {
194194 this . updateListeners . forEach ( listener => listener ( configObj ) ) ;
195- } ) ;
195+ } )
196196 }
197197 }
198198
Original file line number Diff line number Diff line change 1+ /**
2+ * Copyright 2024, Optimizely
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * https://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ type Callback = ( ) => void ;
18+
19+ export const scheduleMicrotaskOrTimeout = ( callback : Callback ) : void => {
20+ if ( typeof queueMicrotask === 'function' ) {
21+ queueMicrotask ( callback ) ;
22+ } else {
23+ setTimeout ( callback ) ;
24+ }
25+ }
You can’t perform that action at this time.
0 commit comments