gd-sprest 9.4.7 → 9.4.8
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.
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
* @param callback The method to execute when the process is working.
|
|
4
4
|
* @param interval The sleep time in milliseconds to wait before calling the callback method
|
|
5
5
|
*/
|
|
6
|
-
export const WebWorker:
|
|
6
|
+
export const WebWorker: IWebWorker;
|
|
7
7
|
|
|
8
8
|
export interface IWebWorker {
|
|
9
|
+
// Constructor
|
|
10
|
+
(callback: () => void, interval: number): IWebWorker;
|
|
11
|
+
|
|
9
12
|
// Stops the worker process
|
|
10
13
|
stop: () => void;
|
|
11
14
|
|
|
@@ -1,31 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WebWorker =
|
|
3
|
+
exports.WebWorker = void 0;
|
|
4
4
|
// Web Worker
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
callback
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
5
|
+
var WebWorker = /** @class */ (function () {
|
|
6
|
+
// Constructor
|
|
7
|
+
function WebWorker(callback, interval) {
|
|
8
|
+
if (interval === void 0) { interval = 1000; }
|
|
9
|
+
var _this = this;
|
|
10
|
+
this._worker = null;
|
|
11
|
+
// Create the worker process
|
|
12
|
+
var blob = new Blob([WorkerCode(interval)], { type: "application/javascript" });
|
|
13
|
+
this._worker = new Worker(URL.createObjectURL(blob));
|
|
14
|
+
// Set the callback method
|
|
15
|
+
this._worker.onmessage = function () {
|
|
16
|
+
// Call the callback method
|
|
17
|
+
callback();
|
|
18
|
+
};
|
|
19
|
+
// Watch the unload event to stop the loop
|
|
20
|
+
window.addEventListener("beforeunload", function () {
|
|
21
|
+
// Stop the loop
|
|
22
|
+
_this.stop();
|
|
23
|
+
_this._worker.terminate();
|
|
24
|
+
});
|
|
25
|
+
}
|
|
22
26
|
// Starts the loop
|
|
23
|
-
|
|
27
|
+
WebWorker.prototype.start = function () { this._worker.postMessage("start"); };
|
|
24
28
|
// Stops the loop
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
WebWorker.prototype.stop = function () { this._worker.postMessage("stop"); };
|
|
30
|
+
return WebWorker;
|
|
31
|
+
}());
|
|
32
|
+
exports.WebWorker = WebWorker;
|
|
29
33
|
// The worker code
|
|
30
34
|
function WorkerCode(interval) {
|
|
31
35
|
return "\nlet interval = [Default Interval];\nlet loopId = null;\nself.onmessage = (e) => {\n // See if the input is a number\n if (typeof (e.data) === \"number\") {\n // Set the interval value\n interval = e.data;\n }\n\n // See if we are stopping the loop\n if (e.data == \"stop\") {\n // Stop the interval and loop id\n clearInterval(loopId);\n loopId = null;\n return;\n }\n\n // See if we are starting the loop\n if (e.data == \"start\") {\n // Ensure it's not already started\n if (loopId != null) { return; }\n\n // Start the loop\n loopId = setInterval(() => {\n // Trigger the callback\n self.postMessage(null);\n }, interval || 1000);\n }\n}".replace('[Default Interval]', interval.toString());
|
package/build/lib/contextInfo.js
CHANGED
|
@@ -810,7 +810,7 @@ var _ContextInfo = /** @class */ (function () {
|
|
|
810
810
|
});
|
|
811
811
|
};
|
|
812
812
|
// Create the process
|
|
813
|
-
this._worker =
|
|
813
|
+
this._worker = new webWorker_1.WebWorker(function () {
|
|
814
814
|
// Refresh the REST API token
|
|
815
815
|
refreshREST();
|
|
816
816
|
// Refresh the Graph API token
|
package/build/rest.js
CHANGED
package/dist/gd-sprest.d.ts
CHANGED
|
@@ -6995,9 +6995,12 @@ declare module 'gd-sprest/helper/methods/webWorker' {
|
|
|
6995
6995
|
* @param callback The method to execute when the process is working.
|
|
6996
6996
|
* @param interval The sleep time in milliseconds to wait before calling the callback method
|
|
6997
6997
|
*/
|
|
6998
|
-
export const WebWorker:
|
|
6998
|
+
export const WebWorker: IWebWorker;
|
|
6999
6999
|
|
|
7000
7000
|
export interface IWebWorker {
|
|
7001
|
+
// Constructor
|
|
7002
|
+
(callback: () => void, interval: number): IWebWorker;
|
|
7003
|
+
|
|
7001
7004
|
// Stops the worker process
|
|
7002
7005
|
stop: () => void;
|
|
7003
7006
|
|