File tree 3 files changed +31
-5
lines changed
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';
24
24
import { IOdpEventApiManager } from './odp_event_api_manager' ;
25
25
import { invalidOdpDataFound } from './odp_utils' ;
26
26
import { IUserAgentParser } from './user_agent_parser' ;
27
+ import { scheduleMicrotaskOrTimeout } from '../../utils/microtasks' ;
27
28
28
29
const MAX_RETRIES = 3 ;
29
30
@@ -393,14 +394,14 @@ export abstract class OdpEventManager implements IOdpEventManager {
393
394
394
395
if ( batch . length > 0 ) {
395
396
// put sending the event on another event loop
396
- queueMicrotask ( async ( ) => {
397
+ scheduleMicrotaskOrTimeout ( async ( ) => {
397
398
let shouldRetry : boolean ;
398
399
let attemptNumber = 0 ;
399
400
do {
400
401
shouldRetry = await this . apiManager . sendEvents ( odpConfig , batch ) ;
401
402
attemptNumber += 1 ;
402
403
} while ( shouldRetry && attemptNumber < this . retries ) ;
403
- } ) ;
404
+ } )
404
405
}
405
406
}
406
407
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import { ERROR_MESSAGES } from '../../utils/enums';
20
20
import { createOptimizelyConfig } from '../optimizely_config' ;
21
21
import { OnReadyResult , OptimizelyConfig , DatafileManager } from '../../shared_types' ;
22
22
import { ProjectConfig , toDatafile , tryCreatingProjectConfig } from '../project_config' ;
23
+ import { scheduleMicrotaskOrTimeout } from '../../utils/microtasks' ;
23
24
24
25
const logger = getLogger ( ) ;
25
26
const MODULE_NAME = 'PROJECT_CONFIG_MANAGER' ;
@@ -189,10 +190,9 @@ export class ProjectConfigManager {
189
190
if ( configObj && oldRevision !== configObj . revision ) {
190
191
this . configObj = configObj ;
191
192
this . optimizelyConfigObj = null ;
192
-
193
- queueMicrotask ( ( ) => {
193
+ scheduleMicrotaskOrTimeout ( ( ) => {
194
194
this . updateListeners . forEach ( listener => listener ( configObj ) ) ;
195
- } ) ;
195
+ } )
196
196
}
197
197
}
198
198
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