@microsoft/1ds-post-js 3.2.1 → 3.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bundle/{ms.post-3.2.1.gbl.js → ms.post-3.2.4.gbl.js} +1071 -966
- package/bundle/ms.post-3.2.4.gbl.js.map +1 -0
- package/bundle/ms.post-3.2.4.gbl.min.js +7 -0
- package/bundle/ms.post-3.2.4.gbl.min.js.map +1 -0
- package/bundle/ms.post-3.2.4.integrity.json +46 -0
- package/bundle/{ms.post-3.2.1.js → ms.post-3.2.4.js} +1071 -966
- package/bundle/ms.post-3.2.4.js.map +1 -0
- package/bundle/ms.post-3.2.4.min.js +7 -0
- package/bundle/ms.post-3.2.4.min.js.map +1 -0
- package/bundle/ms.post.gbl.js +1070 -965
- package/bundle/ms.post.gbl.js.map +1 -1
- package/bundle/ms.post.gbl.min.js +2 -2
- package/bundle/ms.post.gbl.min.js.map +1 -1
- package/bundle/ms.post.integrity.json +17 -17
- package/bundle/ms.post.js +1070 -965
- package/bundle/ms.post.js.map +1 -1
- package/bundle/ms.post.min.js +2 -2
- package/bundle/ms.post.min.js.map +1 -1
- package/dist/ms.post.js +251 -212
- package/dist/ms.post.js.map +1 -1
- package/dist/ms.post.min.js +2 -2
- package/dist/ms.post.min.js.map +1 -1
- package/dist-esm/src/BatchNotificationActions.js +1 -1
- package/dist-esm/src/ClockSkewManager.js +6 -1
- package/dist-esm/src/ClockSkewManager.js.map +1 -1
- package/dist-esm/src/DataModels.js +1 -1
- package/dist-esm/src/EventBatch.d.ts +0 -5
- package/dist-esm/src/EventBatch.js +9 -4
- package/dist-esm/src/EventBatch.js.map +1 -1
- package/dist-esm/src/HttpManager.d.ts +4 -8
- package/dist-esm/src/HttpManager.js +120 -112
- package/dist-esm/src/HttpManager.js.map +1 -1
- package/dist-esm/src/Index.js +1 -1
- package/dist-esm/src/InternalConstants.d.ts +27 -0
- package/dist-esm/src/InternalConstants.js +40 -0
- package/dist-esm/src/InternalConstants.js.map +1 -0
- package/dist-esm/src/KillSwitch.js +7 -2
- package/dist-esm/src/KillSwitch.js.map +1 -1
- package/dist-esm/src/PostChannel.d.ts +3 -6
- package/dist-esm/src/PostChannel.js +97 -73
- package/dist-esm/src/PostChannel.js.map +1 -1
- package/dist-esm/src/RetryPolicy.js +1 -1
- package/dist-esm/src/Serializer.d.ts +1 -1
- package/dist-esm/src/Serializer.js +9 -3
- package/dist-esm/src/Serializer.js.map +1 -1
- package/dist-esm/src/TimeoutOverrideWrapper.d.ts +18 -0
- package/dist-esm/src/TimeoutOverrideWrapper.js +28 -0
- package/dist-esm/src/TimeoutOverrideWrapper.js.map +1 -0
- package/dist-esm/src/typings/XDomainRequest.js +1 -1
- package/package.json +5 -3
- package/src/EventBatch.ts +4 -4
- package/src/HttpManager.ts +74 -71
- package/src/InternalConstants.ts +41 -0
- package/src/KillSwitch.ts +1 -1
- package/src/PostChannel.ts +72 -44
- package/src/Serializer.ts +7 -5
- package/src/TimeoutOverrideWrapper.ts +29 -0
- package/bundle/ms.post-3.2.1.gbl.js.map +0 -1
- package/bundle/ms.post-3.2.1.gbl.min.js +0 -7
- package/bundle/ms.post-3.2.1.gbl.min.js.map +0 -1
- package/bundle/ms.post-3.2.1.integrity.json +0 -46
- package/bundle/ms.post-3.2.1.js.map +0 -1
- package/bundle/ms.post-3.2.1.min.js +0 -7
- package/bundle/ms.post-3.2.1.min.js.map +0 -1
- package/dist-esm/src/Constants.d.ts +0 -25
- package/dist-esm/src/Constants.js +0 -31
- package/dist-esm/src/Constants.js.map +0 -1
- package/src/Constants.ts +0 -28
package/src/PostChannel.ts
CHANGED
|
@@ -3,28 +3,24 @@
|
|
|
3
3
|
* @author Abhilash Panwar (abpanwar); Hector Hernandez (hectorh); Nev Wylie (newylie)
|
|
4
4
|
* @copyright Microsoft 2018-2020
|
|
5
5
|
*/
|
|
6
|
+
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
6
7
|
import {
|
|
7
|
-
BaseTelemetryPlugin,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
addPageUnloadEventListener, addPageHideEventListener, addPageShowEventListener,
|
|
14
|
-
removePageUnloadEventListener, removePageHideEventListener, removePageShowEventListener,
|
|
15
|
-
_throwInternal,
|
|
16
|
-
_eInternalMessageId
|
|
8
|
+
BaseTelemetryPlugin, EventLatencyValue, EventSendType, EventsDiscardedReason, IAppInsightsCore, IChannelControls,
|
|
9
|
+
IExtendedAppInsightsCore, IExtendedConfiguration, IPlugin, IProcessTelemetryContext, IProcessTelemetryUnloadContext, ITelemetryItem,
|
|
10
|
+
ITelemetryUnloadState, NotificationManager, SendRequestReason, _eInternalMessageId, _throwInternal, addPageHideEventListener,
|
|
11
|
+
addPageShowEventListener, addPageUnloadEventListener, arrForEach, createUniqueNamespace, doPerf, eLoggingSeverity, getWindow, isChromium,
|
|
12
|
+
isNumber, isValueAssigned, mergeEvtNamespace, objDefineAccessors, objForEachKey, optimizeObject, removePageHideEventListener,
|
|
13
|
+
removePageShowEventListener, removePageUnloadEventListener, setProcessTelemetryTimings
|
|
17
14
|
} from "@microsoft/1ds-core-js";
|
|
18
15
|
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
EventBatchNotificationReason,
|
|
16
|
+
BE_PROFILE, EventBatchNotificationReason, IChannelConfiguration, IPostChannel, IPostTransmissionTelemetryItem, IXHROverride, NRT_PROFILE,
|
|
17
|
+
RT_PROFILE
|
|
22
18
|
} from "./DataModels";
|
|
23
19
|
import { EventBatch } from "./EventBatch";
|
|
24
20
|
import { HttpManager } from "./HttpManager";
|
|
21
|
+
import { STR_MSA_DEVICE_TICKET, STR_TRACE, STR_USER } from "./InternalConstants";
|
|
25
22
|
import { retryPolicyGetMillisToBackoffForRetry } from "./RetryPolicy";
|
|
26
|
-
import
|
|
27
|
-
import { strMsaDeviceTicket } from "./Constants";
|
|
23
|
+
import { ITimeoutOverrideWrapper, TimeoutClearFunc, TimeoutSetFunc, createTimeoutWrapper } from "./TimeoutOverrideWrapper";
|
|
28
24
|
|
|
29
25
|
const FlushCheckTimer = 0.250; // This needs to be in seconds, so this is 250ms
|
|
30
26
|
const MaxNumberEventPerBatch = 500;
|
|
@@ -32,7 +28,6 @@ const EventsDroppedAtOneTime = 20;
|
|
|
32
28
|
const MaxSendAttempts = 6;
|
|
33
29
|
const MaxSyncUnloadSendAttempts = 2; // Assuming 2 based on beforeunload and unload
|
|
34
30
|
const MaxBackoffCount = 4;
|
|
35
|
-
const globalContext = isWindowObjectAvailable ? window : this;
|
|
36
31
|
const MaxConnections = 2;
|
|
37
32
|
const MaxRequestRetriesBeforeBackoff = 1;
|
|
38
33
|
|
|
@@ -66,7 +61,11 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
66
61
|
public priority = 1011;
|
|
67
62
|
public version = "#version#";
|
|
68
63
|
public _notificationManager: NotificationManager | undefined;
|
|
64
|
+
|
|
65
|
+
/** @deprecated This property is not intended to be used directly please let us know if you have taken a dependency on this property as it may be removed in a future release */
|
|
69
66
|
public _setTimeoutOverride: typeof setTimeout;
|
|
67
|
+
|
|
68
|
+
/** @deprecated This property is not intended to be used directly please let us know if you have taken a dependency on this property as it may be removed in a future release */
|
|
70
69
|
public _clearTimeoutOverride: typeof clearTimeout;
|
|
71
70
|
|
|
72
71
|
constructor() {
|
|
@@ -97,10 +96,10 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
97
96
|
let _delayedBatchReason: SendRequestReason;
|
|
98
97
|
let _optimizeObject: boolean = true;
|
|
99
98
|
let _isPageUnloadTriggered = false;
|
|
100
|
-
let _disableXhrSync = false;
|
|
101
99
|
let _maxEventSendAttempts: number = MaxSendAttempts;
|
|
102
100
|
let _maxUnloadEventSendAttempts: number = MaxSyncUnloadSendAttempts;
|
|
103
101
|
let _evtNamespace: string | string[];
|
|
102
|
+
let _timeoutWrapper: ITimeoutOverrideWrapper;
|
|
104
103
|
|
|
105
104
|
dynamicProto(PostChannel, this, (_self, _base) => {
|
|
106
105
|
_initDefaults();
|
|
@@ -121,8 +120,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
121
120
|
let ctx = _self._getTelCtx();
|
|
122
121
|
coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {};
|
|
123
122
|
_config = ctx.getExtCfg(_self.identifier);
|
|
124
|
-
|
|
125
|
-
_self._clearTimeoutOverride = _config.clearTimeoutOverride ? _config.clearTimeoutOverride : clearTimeout.bind(globalContext);
|
|
123
|
+
_timeoutWrapper = createTimeoutWrapper(_config.setTimeoutOverride, _config.clearTimeoutOverride);
|
|
126
124
|
|
|
127
125
|
// Only try and use the optimizeObject() if this appears to be a chromium based browser and it has not been explicitly disabled
|
|
128
126
|
_optimizeObject = !_config.disableOptimizeObj && isChromium();
|
|
@@ -141,7 +139,6 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
141
139
|
_autoFlushEventsLimit = _config.autoFlushEventsLimit;
|
|
142
140
|
}
|
|
143
141
|
|
|
144
|
-
_disableXhrSync = _config.disableXhrSync;
|
|
145
142
|
if (isNumber(_config[strMaxEventRetryAttempts])) {
|
|
146
143
|
_maxEventSendAttempts = _config[strMaxEventRetryAttempts];
|
|
147
144
|
}
|
|
@@ -272,15 +269,15 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
272
269
|
}
|
|
273
270
|
|
|
274
271
|
// Remove extra AI properties if present
|
|
275
|
-
if (event.ext && event.ext[
|
|
276
|
-
delete (event.ext[
|
|
272
|
+
if (event.ext && event.ext[STR_TRACE]) {
|
|
273
|
+
delete (event.ext[STR_TRACE]);
|
|
277
274
|
}
|
|
278
|
-
if (event.ext && event.ext[
|
|
279
|
-
delete (event.ext[
|
|
275
|
+
if (event.ext && event.ext[STR_USER] && event.ext[STR_USER]["id"]) {
|
|
276
|
+
delete (event.ext[STR_USER]["id"]);
|
|
280
277
|
}
|
|
281
278
|
|
|
282
279
|
// v8 performance optimization for iterating over the keys
|
|
283
|
-
if (_optimizeObject) {
|
|
280
|
+
if (_optimizeObject) {setProcessTelemetryTimings
|
|
284
281
|
event.ext = optimizeObject(event.ext);
|
|
285
282
|
if (event.baseData) {
|
|
286
283
|
event.baseData = optimizeObject(event.baseData);
|
|
@@ -421,20 +418,19 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
421
418
|
|
|
422
419
|
_self.flush = (async = true, callback?: () => void, sendReason?: SendRequestReason) => {
|
|
423
420
|
if (!_paused) {
|
|
424
|
-
// Clear the normal schedule timer as we are going to try and flush ASAP
|
|
425
|
-
_clearScheduledTimer();
|
|
426
421
|
|
|
427
422
|
sendReason = sendReason || SendRequestReason.ManualFlush;
|
|
428
423
|
|
|
429
424
|
if (async) {
|
|
430
|
-
// Move all queued events to the HttpManager
|
|
431
|
-
_queueBatches(EventLatencyValue.Normal, EventSendType.Batched, sendReason);
|
|
432
|
-
|
|
433
|
-
// All events (should) have been queue -- lets just make sure the queue counts are correct to avoid queue exhaustion (previous bug #9685112)
|
|
434
|
-
_resetQueueCounts();
|
|
435
|
-
|
|
436
425
|
if (_flushCallbackTimerId == null) {
|
|
426
|
+
// Clear the normal schedule timer as we are going to try and flush ASAP
|
|
427
|
+
_clearScheduledTimer();
|
|
428
|
+
|
|
429
|
+
// Move all queued events to the HttpManager so that we don't discard new events (Auto flush scenario)
|
|
430
|
+
_queueBatches(EventLatencyValue.Normal, EventSendType.Batched, sendReason);
|
|
431
|
+
|
|
437
432
|
_flushCallbackTimerId = _createTimer(() => {
|
|
433
|
+
_flushCallbackTimerId = null;
|
|
438
434
|
_flushImpl(callback, sendReason);
|
|
439
435
|
}, 0);
|
|
440
436
|
} else {
|
|
@@ -443,18 +439,26 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
443
439
|
_flushCallbackQueue.push(callback);
|
|
444
440
|
}
|
|
445
441
|
} else {
|
|
442
|
+
// Clear the normal schedule timer as we are going to try and flush ASAP
|
|
443
|
+
let cleared = _clearScheduledTimer();
|
|
444
|
+
|
|
446
445
|
// Now cause all queued events to be sent synchronously
|
|
447
446
|
_sendEventsForLatencyAndAbove(EventLatencyValue.Normal, EventSendType.Synchronous, sendReason);
|
|
448
447
|
|
|
449
448
|
if (callback !== null && callback !== undefined) {
|
|
450
449
|
callback();
|
|
451
450
|
}
|
|
451
|
+
|
|
452
|
+
if (cleared) {
|
|
453
|
+
// restart the normal event timer if it was cleared
|
|
454
|
+
_scheduleTimer();
|
|
455
|
+
}
|
|
452
456
|
}
|
|
453
457
|
}
|
|
454
458
|
};
|
|
455
459
|
|
|
456
460
|
_self.setMsaAuthTicket = (ticket: string) => {
|
|
457
|
-
_httpManager.addHeader(
|
|
461
|
+
_httpManager.addHeader(STR_MSA_DEVICE_TICKET, ticket);
|
|
458
462
|
};
|
|
459
463
|
|
|
460
464
|
_self.hasEvents = _hasEvents;
|
|
@@ -572,10 +576,10 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
572
576
|
_delayedBatchReason = null;
|
|
573
577
|
_optimizeObject = true;
|
|
574
578
|
_isPageUnloadTriggered = false;
|
|
575
|
-
_disableXhrSync = false;
|
|
576
579
|
_maxEventSendAttempts = MaxSendAttempts;
|
|
577
580
|
_maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
|
|
578
581
|
_evtNamespace = null;
|
|
582
|
+
_timeoutWrapper = createTimeoutWrapper();
|
|
579
583
|
_httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRequestRetriesBeforeBackoff, {
|
|
580
584
|
requeue: _requeueEvents,
|
|
581
585
|
send: _sendingEvent,
|
|
@@ -583,7 +587,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
583
587
|
drop: _eventsDropped,
|
|
584
588
|
rspFail: _eventsResponseFail,
|
|
585
589
|
oth: _otherEvent
|
|
586
|
-
});
|
|
590
|
+
}, _timeoutWrapper);
|
|
587
591
|
|
|
588
592
|
_initializeProfiles();
|
|
589
593
|
_clearQueues();
|
|
@@ -601,14 +605,17 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
601
605
|
timerMultiplier = retryPolicyGetMillisToBackoffForRetry(_currentBackoffCount - 1);
|
|
602
606
|
}
|
|
603
607
|
|
|
604
|
-
return
|
|
608
|
+
return _timeoutWrapper.set(theTimerFunc, timeOut * timerMultiplier);
|
|
605
609
|
}
|
|
606
610
|
function _clearScheduledTimer() {
|
|
607
611
|
if (_scheduledTimerId !== null) {
|
|
608
|
-
|
|
612
|
+
_timeoutWrapper.clear(_scheduledTimerId);
|
|
609
613
|
_scheduledTimerId = null;
|
|
610
614
|
_timerCount = 0;
|
|
615
|
+
return true;
|
|
611
616
|
}
|
|
617
|
+
|
|
618
|
+
return false;
|
|
612
619
|
}
|
|
613
620
|
|
|
614
621
|
// Try to send all queued events using beacons if available
|
|
@@ -617,7 +624,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
617
624
|
|
|
618
625
|
// Cancel all flush callbacks
|
|
619
626
|
if (_flushCallbackTimerId) {
|
|
620
|
-
|
|
627
|
+
_timeoutWrapper.clear(_flushCallbackTimerId);
|
|
621
628
|
_flushCallbackTimerId = null;
|
|
622
629
|
}
|
|
623
630
|
|
|
@@ -829,6 +836,9 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
829
836
|
// Add any additional queued events and cause all queued events to be sent asynchronously
|
|
830
837
|
_sendEventsForLatencyAndAbove(EventLatencyValue.Normal, EventSendType.Batched, sendReason);
|
|
831
838
|
|
|
839
|
+
// All events (should) have been queue -- lets just make sure the queue counts are correct to avoid queue exhaustion (previous bug #9685112)
|
|
840
|
+
_resetQueueCounts();
|
|
841
|
+
|
|
832
842
|
_waitForIdleManager(() => {
|
|
833
843
|
// Only called AFTER the httpManager does not have any outstanding requests
|
|
834
844
|
if (callback) {
|
|
@@ -836,14 +846,16 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
836
846
|
}
|
|
837
847
|
|
|
838
848
|
if (_flushCallbackQueue.length > 0) {
|
|
839
|
-
_flushCallbackTimerId = _createTimer(() =>
|
|
849
|
+
_flushCallbackTimerId = _createTimer(() => {
|
|
850
|
+
_flushCallbackTimerId = null;
|
|
851
|
+
_flushImpl(_flushCallbackQueue.shift(), sendReason);
|
|
852
|
+
}, 0);
|
|
840
853
|
} else {
|
|
841
854
|
// No more flush requests
|
|
842
855
|
_flushCallbackTimerId = null;
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
}
|
|
856
|
+
|
|
857
|
+
// Restart the normal timer schedule
|
|
858
|
+
_scheduleTimer();
|
|
847
859
|
}
|
|
848
860
|
});
|
|
849
861
|
}
|
|
@@ -853,6 +865,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
853
865
|
callback();
|
|
854
866
|
} else {
|
|
855
867
|
_flushCallbackTimerId = _createTimer(() => {
|
|
868
|
+
_flushCallbackTimerId = null;
|
|
856
869
|
_waitForIdleManager(callback);
|
|
857
870
|
}, FlushCheckTimer);
|
|
858
871
|
}
|
|
@@ -1008,6 +1021,21 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
1008
1021
|
_autoFlushBatchLimit = 0;
|
|
1009
1022
|
}
|
|
1010
1023
|
}
|
|
1024
|
+
|
|
1025
|
+
// Provided for backward compatibility they are not "expected" to be in current use but they are public
|
|
1026
|
+
objDefineAccessors(_self, "_setTimeoutOverride",
|
|
1027
|
+
() => _timeoutWrapper.set,
|
|
1028
|
+
(value: TimeoutSetFunc<any>) => {
|
|
1029
|
+
// Recreate the timeout wrapper
|
|
1030
|
+
_timeoutWrapper = createTimeoutWrapper(value, _timeoutWrapper.clear);
|
|
1031
|
+
});
|
|
1032
|
+
|
|
1033
|
+
objDefineAccessors(_self, "_clearTimeoutOverride",
|
|
1034
|
+
() => _timeoutWrapper.clear,
|
|
1035
|
+
(value: TimeoutClearFunc<any>) => {
|
|
1036
|
+
// Recreate the timeout wrapper
|
|
1037
|
+
_timeoutWrapper = createTimeoutWrapper(_timeoutWrapper.set, value);
|
|
1038
|
+
});
|
|
1011
1039
|
});
|
|
1012
1040
|
}
|
|
1013
1041
|
|
package/src/Serializer.ts
CHANGED
|
@@ -3,14 +3,16 @@
|
|
|
3
3
|
* @author Abhilash Panwar (abpanwar); Hector Hernandez (hectorh); Nev Wylie (newylie)
|
|
4
4
|
* @copyright Microsoft 2018-2020
|
|
5
5
|
*/
|
|
6
|
+
// @skip-file-minify
|
|
7
|
+
|
|
8
|
+
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
6
9
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
EventSendType, FieldValueSanitizerFunc, FieldValueSanitizerType, IEventProperty, IPerfManagerProvider, IValueSanitizer,
|
|
11
|
+
SendRequestReason, arrIndexOf, doPerf, getCommonSchemaMetaData, getTenantId, isArray, isValueAssigned, objForEachKey, sanitizeProperty,
|
|
12
|
+
strStartsWith
|
|
10
13
|
} from "@microsoft/1ds-core-js";
|
|
11
|
-
import { IPostTransmissionTelemetryItem
|
|
14
|
+
import { IPostTransmissionTelemetryItem } from "./DataModels";
|
|
12
15
|
import { EventBatch } from "./EventBatch";
|
|
13
|
-
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
14
16
|
|
|
15
17
|
/**
|
|
16
18
|
* Note: This is an optimization for V8-based browsers. When V8 concatenates a string,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TimeoutOverrideWrapper.ts
|
|
3
|
+
* @author Nev Wylie (newylie)
|
|
4
|
+
* @copyright Microsoft 2022
|
|
5
|
+
* Simple internal timeout wrapper
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export type TimeoutSetFunc<T = any> = (callback: (...args: any[]) => void, ms: number, ...args: any[]) => T;
|
|
9
|
+
export type TimeoutClearFunc<T = any> = (timeoutId?: T) => void;
|
|
10
|
+
|
|
11
|
+
export interface ITimeoutOverrideWrapper<T = any> {
|
|
12
|
+
set: TimeoutSetFunc<T>;
|
|
13
|
+
clear: TimeoutClearFunc<T>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function defaultSetTimeout<T = any>(callback: (...args: any[]) => void, ms: number, ...args: any[]): T {
|
|
17
|
+
return setTimeout(callback, ms, args) as any;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function defaultClearTimeout<T = any>(timeoutId?: T): void {
|
|
21
|
+
clearTimeout(timeoutId as any);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function createTimeoutWrapper<T = any>(argSetTimeout?: TimeoutSetFunc<T>, argClearTimeout?: TimeoutClearFunc<T>) {
|
|
25
|
+
return {
|
|
26
|
+
set: argSetTimeout || defaultSetTimeout,
|
|
27
|
+
clear: argClearTimeout || defaultClearTimeout
|
|
28
|
+
}
|
|
29
|
+
}
|