@loaders.gl/loader-utils 4.0.0-alpha.1 → 4.0.0-alpha.11
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/dist/es5/index.js +328 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/json-loader.js +44 -0
- package/dist/es5/json-loader.js.map +1 -0
- package/dist/es5/lib/binary-utils/array-buffer-utils.js +80 -0
- package/dist/es5/lib/binary-utils/array-buffer-utils.js.map +1 -0
- package/dist/es5/lib/binary-utils/dataview-copy-utils.js +58 -0
- package/dist/es5/lib/binary-utils/dataview-copy-utils.js.map +1 -0
- package/dist/es5/lib/binary-utils/get-first-characters.js +31 -0
- package/dist/es5/lib/binary-utils/get-first-characters.js.map +1 -0
- package/dist/es5/lib/binary-utils/memory-conversion-utils.js +44 -0
- package/dist/es5/lib/binary-utils/memory-conversion-utils.js.map +1 -0
- package/dist/es5/lib/binary-utils/memory-copy-utils.js +34 -0
- package/dist/es5/lib/binary-utils/memory-copy-utils.js.map +1 -0
- package/dist/es5/lib/env-utils/assert.js +12 -0
- package/dist/es5/lib/env-utils/assert.js.map +1 -0
- package/dist/es5/lib/env-utils/globals.js +30 -0
- package/dist/es5/lib/env-utils/globals.js.map +1 -0
- package/dist/es5/lib/filesystems/node-filesystem.js +210 -0
- package/dist/es5/lib/filesystems/node-filesystem.js.map +1 -0
- package/dist/es5/lib/filesystems/readable-file.js +91 -0
- package/dist/es5/lib/filesystems/readable-file.js.map +1 -0
- package/dist/es5/lib/filesystems/writable-file.js +82 -0
- package/dist/es5/lib/filesystems/writable-file.js.map +1 -0
- package/dist/es5/lib/iterators/async-iteration.js +190 -0
- package/dist/es5/lib/iterators/async-iteration.js.map +1 -0
- package/dist/es5/lib/iterators/text-iterators.js +305 -0
- package/dist/es5/lib/iterators/text-iterators.js.map +1 -0
- package/dist/es5/lib/node/buffer.browser.js +14 -0
- package/dist/es5/lib/node/buffer.browser.js.map +1 -0
- package/dist/es5/lib/node/buffer.js +27 -0
- package/dist/es5/lib/node/buffer.js.map +1 -0
- package/dist/es5/lib/node/fs.js +88 -0
- package/dist/es5/lib/node/fs.js.map +1 -0
- package/dist/es5/lib/node/promisify.js +36 -0
- package/dist/es5/lib/node/promisify.js.map +1 -0
- package/dist/es5/lib/node/stream.js +16 -0
- package/dist/es5/lib/node/stream.js.map +1 -0
- package/dist/es5/lib/option-utils/merge-loader-options.js +30 -0
- package/dist/es5/lib/option-utils/merge-loader-options.js.map +1 -0
- package/dist/es5/lib/parser-utils/parse-json.js +15 -0
- package/dist/es5/lib/parser-utils/parse-json.js.map +1 -0
- package/dist/es5/lib/path-utils/file-aliases.js +33 -0
- package/dist/es5/lib/path-utils/file-aliases.js.map +1 -0
- package/dist/es5/lib/path-utils/get-cwd.js +15 -0
- package/dist/es5/lib/path-utils/get-cwd.js.map +1 -0
- package/dist/es5/lib/path-utils/path.js +136 -0
- package/dist/es5/lib/path-utils/path.js.map +1 -0
- package/dist/es5/lib/request-utils/request-scheduler.js +150 -0
- package/dist/es5/lib/request-utils/request-scheduler.js.map +1 -0
- package/dist/es5/lib/worker-loader-utils/create-loader-worker.js +142 -0
- package/dist/es5/lib/worker-loader-utils/create-loader-worker.js.map +1 -0
- package/dist/es5/lib/worker-loader-utils/encode-with-worker.js +18 -0
- package/dist/es5/lib/worker-loader-utils/encode-with-worker.js.map +1 -0
- package/dist/es5/lib/worker-loader-utils/parse-with-worker.js +115 -0
- package/dist/es5/lib/worker-loader-utils/parse-with-worker.js.map +1 -0
- package/dist/es5/types.js +2 -0
- package/dist/es5/types.js.map +1 -0
- package/dist/es5/workers/json-worker.js +6 -0
- package/dist/es5/workers/json-worker.js.map +1 -0
- package/dist/esm/index.js +29 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/json-loader.js +18 -0
- package/dist/esm/json-loader.js.map +1 -0
- package/dist/esm/lib/binary-utils/array-buffer-utils.js +52 -0
- package/dist/esm/lib/binary-utils/array-buffer-utils.js.map +1 -0
- package/dist/{lib/binary-utils/binary-copy-utils.js → esm/lib/binary-utils/dataview-copy-utils.js} +27 -4
- package/dist/esm/lib/binary-utils/dataview-copy-utils.js.map +1 -0
- package/dist/esm/lib/binary-utils/get-first-characters.js +24 -0
- package/dist/esm/lib/binary-utils/get-first-characters.js.map +1 -0
- package/dist/esm/lib/binary-utils/memory-conversion-utils.js +31 -0
- package/dist/esm/lib/binary-utils/memory-conversion-utils.js.map +1 -0
- package/dist/esm/lib/binary-utils/memory-copy-utils.js +26 -0
- package/dist/esm/lib/binary-utils/memory-copy-utils.js.map +1 -0
- package/dist/esm/lib/env-utils/assert.js +6 -0
- package/dist/esm/lib/env-utils/assert.js.map +1 -0
- package/dist/esm/lib/env-utils/globals.js +16 -0
- package/dist/esm/lib/env-utils/globals.js.map +1 -0
- package/dist/esm/lib/filesystems/node-filesystem.js +53 -0
- package/dist/esm/lib/filesystems/node-filesystem.js.map +1 -0
- package/dist/esm/lib/filesystems/readable-file.js +20 -0
- package/dist/esm/lib/filesystems/readable-file.js.map +1 -0
- package/dist/esm/lib/filesystems/writable-file.js +20 -0
- package/dist/esm/lib/filesystems/writable-file.js.map +1 -0
- package/dist/esm/lib/iterators/async-iteration.js +32 -0
- package/dist/esm/lib/iterators/async-iteration.js.map +1 -0
- package/dist/esm/lib/iterators/text-iterators.js +47 -0
- package/dist/esm/lib/iterators/text-iterators.js.map +1 -0
- package/dist/esm/lib/node/buffer.browser.js +7 -0
- package/dist/esm/lib/node/buffer.browser.js.map +1 -0
- package/dist/esm/lib/node/buffer.js +20 -0
- package/dist/esm/lib/node/buffer.js.map +1 -0
- package/dist/esm/lib/node/fs.js +40 -0
- package/dist/esm/lib/node/fs.js.map +1 -0
- package/dist/esm/lib/node/promisify.js +10 -0
- package/dist/esm/lib/node/promisify.js.map +1 -0
- package/dist/esm/lib/node/stream.js +7 -0
- package/dist/esm/lib/node/stream.js.map +1 -0
- package/dist/esm/lib/option-utils/merge-loader-options.js +17 -0
- package/dist/esm/lib/option-utils/merge-loader-options.js.map +1 -0
- package/dist/esm/lib/parser-utils/parse-json.js +9 -0
- package/dist/esm/lib/parser-utils/parse-json.js.map +1 -0
- package/dist/esm/lib/path-utils/file-aliases.js +24 -0
- package/dist/esm/lib/path-utils/file-aliases.js.map +1 -0
- package/dist/esm/lib/path-utils/get-cwd.js +9 -0
- package/dist/esm/lib/path-utils/get-cwd.js.map +1 -0
- package/dist/esm/lib/path-utils/path.js +127 -0
- package/dist/esm/lib/path-utils/path.js.map +1 -0
- package/dist/esm/lib/request-utils/request-scheduler.js +120 -0
- package/dist/esm/lib/request-utils/request-scheduler.js.map +1 -0
- package/dist/esm/lib/worker-loader-utils/create-loader-worker.js +95 -0
- package/dist/esm/lib/worker-loader-utils/create-loader-worker.js.map +1 -0
- package/dist/esm/lib/worker-loader-utils/encode-with-worker.js +12 -0
- package/dist/esm/lib/worker-loader-utils/encode-with-worker.js.map +1 -0
- package/dist/esm/lib/worker-loader-utils/parse-with-worker.js +63 -0
- package/dist/esm/lib/worker-loader-utils/parse-with-worker.js.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/workers/json-worker.js +4 -0
- package/dist/esm/workers/json-worker.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +122 -26
- package/dist/json-loader.d.ts +9 -0
- package/dist/json-loader.d.ts.map +1 -0
- package/dist/json-loader.js +24 -18
- package/dist/lib/binary-utils/array-buffer-utils.d.ts +27 -0
- package/dist/lib/binary-utils/array-buffer-utils.d.ts.map +1 -0
- package/dist/lib/binary-utils/array-buffer-utils.js +78 -80
- package/dist/lib/binary-utils/dataview-copy-utils.d.ts +43 -0
- package/dist/lib/binary-utils/dataview-copy-utils.d.ts.map +1 -0
- package/dist/lib/binary-utils/dataview-copy-utils.js +97 -0
- package/dist/lib/binary-utils/get-first-characters.d.ts +17 -0
- package/dist/lib/binary-utils/get-first-characters.d.ts.map +1 -0
- package/dist/lib/binary-utils/get-first-characters.js +43 -25
- package/dist/lib/binary-utils/memory-conversion-utils.d.ts +15 -0
- package/dist/lib/binary-utils/memory-conversion-utils.d.ts.map +1 -0
- package/dist/lib/binary-utils/memory-conversion-utils.js +73 -0
- package/dist/lib/binary-utils/memory-copy-utils.d.ts +25 -0
- package/dist/lib/binary-utils/memory-copy-utils.d.ts.map +1 -0
- package/dist/lib/binary-utils/memory-copy-utils.js +58 -24
- package/dist/lib/env-utils/assert.d.ts +6 -0
- package/dist/lib/env-utils/assert.d.ts.map +1 -0
- package/dist/lib/env-utils/assert.js +12 -5
- package/dist/lib/env-utils/globals.d.ts +15 -0
- package/dist/lib/env-utils/globals.d.ts.map +1 -0
- package/dist/lib/env-utils/globals.js +23 -9
- package/dist/lib/filesystems/node-filesystem.d.ts +39 -0
- package/dist/lib/filesystems/node-filesystem.d.ts.map +1 -0
- package/dist/lib/filesystems/node-filesystem.js +72 -59
- package/dist/lib/filesystems/readable-file.d.ts +10 -0
- package/dist/lib/filesystems/readable-file.d.ts.map +1 -0
- package/dist/lib/filesystems/readable-file.js +25 -0
- package/dist/lib/filesystems/writable-file.d.ts +18 -0
- package/dist/lib/filesystems/writable-file.d.ts.map +1 -0
- package/dist/lib/filesystems/writable-file.js +48 -0
- package/dist/lib/iterators/async-iteration.d.ts +20 -0
- package/dist/lib/iterators/async-iteration.d.ts.map +1 -0
- package/dist/lib/iterators/async-iteration.js +49 -35
- package/dist/lib/iterators/text-iterators.d.ts +19 -0
- package/dist/lib/iterators/text-iterators.d.ts.map +1 -0
- package/dist/lib/iterators/text-iterators.js +56 -41
- package/dist/lib/node/buffer.browser.d.ts +12 -0
- package/dist/lib/node/buffer.browser.d.ts.map +1 -0
- package/dist/lib/node/buffer.browser.js +22 -0
- package/dist/lib/node/buffer.d.ts +12 -0
- package/dist/lib/node/buffer.d.ts.map +1 -0
- package/dist/lib/node/buffer.js +33 -25
- package/dist/lib/node/fs.d.ts +25 -0
- package/dist/lib/node/fs.d.ts.map +1 -0
- package/dist/lib/node/fs.js +48 -26
- package/dist/lib/node/promisify.d.ts +13 -0
- package/dist/lib/node/promisify.d.ts.map +1 -0
- package/dist/lib/node/promisify.js +22 -0
- package/dist/lib/node/stream.d.ts +4 -0
- package/dist/lib/node/stream.d.ts.map +1 -0
- package/dist/lib/node/stream.js +17 -0
- package/dist/lib/option-utils/merge-loader-options.d.ts +9 -0
- package/dist/lib/option-utils/merge-loader-options.d.ts.map +1 -0
- package/dist/lib/option-utils/merge-loader-options.js +27 -0
- package/dist/lib/parser-utils/parse-json.d.ts +5 -0
- package/dist/lib/parser-utils/parse-json.d.ts.map +1 -0
- package/dist/lib/parser-utils/parse-json.js +15 -8
- package/dist/lib/path-utils/file-aliases.d.ts +17 -0
- package/dist/lib/path-utils/file-aliases.d.ts.map +1 -0
- package/dist/lib/path-utils/file-aliases.js +40 -19
- package/dist/lib/path-utils/get-cwd.d.ts +2 -0
- package/dist/lib/path-utils/get-cwd.d.ts.map +1 -0
- package/dist/lib/path-utils/get-cwd.js +12 -0
- package/dist/lib/path-utils/path.d.ts +24 -0
- package/dist/lib/path-utils/path.d.ts.map +1 -0
- package/dist/lib/path-utils/path.js +173 -19
- package/dist/lib/request-utils/request-scheduler.d.ts +62 -0
- package/dist/lib/request-utils/request-scheduler.d.ts.map +1 -0
- package/dist/lib/request-utils/request-scheduler.js +127 -131
- package/dist/lib/worker-loader-utils/create-loader-worker.d.ts +7 -0
- package/dist/lib/worker-loader-utils/create-loader-worker.d.ts.map +1 -0
- package/dist/lib/worker-loader-utils/create-loader-worker.js +92 -96
- package/dist/lib/worker-loader-utils/encode-with-worker.d.ts +8 -0
- package/dist/lib/worker-loader-utils/encode-with-worker.d.ts.map +1 -0
- package/dist/lib/worker-loader-utils/encode-with-worker.js +21 -0
- package/dist/lib/worker-loader-utils/parse-with-worker.d.ts +15 -0
- package/dist/lib/worker-loader-utils/parse-with-worker.d.ts.map +1 -0
- package/dist/lib/worker-loader-utils/parse-with-worker.js +77 -60
- package/dist/types.d.ts +257 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -2
- package/dist/workers/json-worker.d.ts +2 -0
- package/dist/workers/json-worker.d.ts.map +1 -0
- package/dist/workers/json-worker.js +5 -4
- package/package.json +14 -24
- package/src/index.ts +40 -19
- package/src/json-loader.ts +5 -4
- package/src/lib/binary-utils/array-buffer-utils.ts +4 -40
- package/src/lib/binary-utils/{binary-copy-utils.ts → dataview-copy-utils.ts} +57 -5
- package/src/lib/binary-utils/get-first-characters.ts +17 -1
- package/src/lib/binary-utils/memory-conversion-utils.ts +53 -0
- package/src/lib/filesystems/readable-file.ts +30 -0
- package/src/lib/filesystems/writable-file.ts +44 -0
- package/src/lib/node/buffer.browser.ts +20 -0
- package/src/lib/node/buffer.ts +12 -11
- package/src/lib/node/fs.ts +51 -16
- package/src/lib/node/promisify.ts +70 -0
- package/src/lib/node/stream.ts +18 -0
- package/src/lib/option-utils/merge-loader-options.ts +35 -0
- package/src/lib/path-utils/get-cwd.ts +9 -0
- package/src/lib/path-utils/path.ts +138 -4
- package/src/lib/worker-loader-utils/create-loader-worker.ts +3 -2
- package/src/lib/worker-loader-utils/encode-with-worker.ts +21 -0
- package/src/lib/worker-loader-utils/parse-with-worker.ts +16 -3
- package/src/types.ts +211 -93
- package/dist/index.js.map +0 -1
- package/dist/json-loader.js.map +0 -1
- package/dist/lib/binary-utils/array-buffer-utils.js.map +0 -1
- package/dist/lib/binary-utils/binary-copy-utils.js.map +0 -1
- package/dist/lib/binary-utils/buffer-utils.js +0 -16
- package/dist/lib/binary-utils/buffer-utils.js.map +0 -1
- package/dist/lib/binary-utils/encode-utils.js +0 -31
- package/dist/lib/binary-utils/encode-utils.js.map +0 -1
- package/dist/lib/binary-utils/get-first-characters.js.map +0 -1
- package/dist/lib/binary-utils/memory-copy-utils.js.map +0 -1
- package/dist/lib/env-utils/assert.js.map +0 -1
- package/dist/lib/env-utils/globals.js.map +0 -1
- package/dist/lib/filesystems/node-filesystem.js.map +0 -1
- package/dist/lib/iterators/async-iteration.js.map +0 -1
- package/dist/lib/iterators/text-iterators.js.map +0 -1
- package/dist/lib/node/buffer.js.map +0 -1
- package/dist/lib/node/fs.js.map +0 -1
- package/dist/lib/node/util.js +0 -3
- package/dist/lib/node/util.js.map +0 -1
- package/dist/lib/parser-utils/parse-json.js.map +0 -1
- package/dist/lib/path-utils/file-aliases.js.map +0 -1
- package/dist/lib/path-utils/path.js.map +0 -1
- package/dist/lib/request-utils/request-scheduler.js.map +0 -1
- package/dist/lib/worker-loader-utils/create-loader-worker.js.map +0 -1
- package/dist/lib/worker-loader-utils/parse-with-worker.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/workers/json-worker.js.map +0 -1
- package/src/lib/binary-utils/buffer-utils.ts +0 -28
- package/src/lib/binary-utils/encode-utils.ts +0 -32
- package/src/lib/node/util.ts +0 -4
|
@@ -1,146 +1,142 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const stats_1 = require("@probe.gl/stats");
|
|
3
4
|
const STAT_QUEUED_REQUESTS = 'Queued Requests';
|
|
4
5
|
const STAT_ACTIVE_REQUESTS = 'Active Requests';
|
|
5
6
|
const STAT_CANCELLED_REQUESTS = 'Cancelled Requests';
|
|
6
7
|
const STAT_QUEUED_REQUESTS_EVER = 'Queued Requests Ever';
|
|
7
8
|
const STAT_ACTIVE_REQUESTS_EVER = 'Active Requests Ever';
|
|
8
9
|
const DEFAULT_PROPS = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
id: 'request-scheduler',
|
|
11
|
+
// Specifies if the request scheduler should throttle incoming requests, mainly for comparative testing
|
|
12
|
+
throttleRequests: true,
|
|
13
|
+
// The maximum number of simultaneous active requests. Un-throttled requests do not observe this limit.
|
|
14
|
+
maxRequests: 6
|
|
12
15
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
});
|
|
33
|
-
this.stats.get(STAT_QUEUED_REQUESTS);
|
|
34
|
-
this.stats.get(STAT_ACTIVE_REQUESTS);
|
|
35
|
-
this.stats.get(STAT_CANCELLED_REQUESTS);
|
|
36
|
-
this.stats.get(STAT_QUEUED_REQUESTS_EVER);
|
|
37
|
-
this.stats.get(STAT_ACTIVE_REQUESTS_EVER);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
scheduleRequest(handle, getPriority = () => 0) {
|
|
41
|
-
if (!this.props.throttleRequests) {
|
|
42
|
-
return Promise.resolve({
|
|
43
|
-
done: () => {}
|
|
44
|
-
});
|
|
16
|
+
/**
|
|
17
|
+
* Used to issue a request, without having them "deeply queued" by the browser.
|
|
18
|
+
* @todo - Track requests globally, across multiple servers
|
|
19
|
+
*/
|
|
20
|
+
class RequestScheduler {
|
|
21
|
+
constructor(props = {}) {
|
|
22
|
+
this.activeRequestCount = 0;
|
|
23
|
+
/** Tracks the number of active requests and prioritizes/cancels queued requests. */
|
|
24
|
+
this.requestQueue = [];
|
|
25
|
+
this.requestMap = new Map();
|
|
26
|
+
this.deferredUpdate = null;
|
|
27
|
+
this.props = { ...DEFAULT_PROPS, ...props };
|
|
28
|
+
// Returns the statistics used by the request scheduler.
|
|
29
|
+
this.stats = new stats_1.Stats({ id: this.props.id });
|
|
30
|
+
this.stats.get(STAT_QUEUED_REQUESTS);
|
|
31
|
+
this.stats.get(STAT_ACTIVE_REQUESTS);
|
|
32
|
+
this.stats.get(STAT_CANCELLED_REQUESTS);
|
|
33
|
+
this.stats.get(STAT_QUEUED_REQUESTS_EVER);
|
|
34
|
+
this.stats.get(STAT_ACTIVE_REQUESTS_EVER);
|
|
45
35
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
this.requestMap.
|
|
79
|
-
this.activeRequestCount--;
|
|
80
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Called by an application that wants to issue a request, without having it deeply queued by the browser
|
|
38
|
+
*
|
|
39
|
+
* When the returned promise resolved, it is OK for the application to issue a request.
|
|
40
|
+
* The promise resolves to an object that contains a `done` method.
|
|
41
|
+
* When the application's request has completed (or failed), the application must call the `done` function
|
|
42
|
+
*
|
|
43
|
+
* @param handle
|
|
44
|
+
* @param getPriority will be called when request "slots" open up,
|
|
45
|
+
* allowing the caller to update priority or cancel the request
|
|
46
|
+
* Highest priority executes first, priority < 0 cancels the request
|
|
47
|
+
* @returns a promise
|
|
48
|
+
* - resolves to a object (with a `done` field) when the request can be issued without queueing,
|
|
49
|
+
* - resolves to `null` if the request has been cancelled (by the callback return < 0).
|
|
50
|
+
* In this case the application should not issue the request
|
|
51
|
+
*/
|
|
52
|
+
scheduleRequest(handle, getPriority = () => 0) {
|
|
53
|
+
// Allows throttling to be disabled
|
|
54
|
+
if (!this.props.throttleRequests) {
|
|
55
|
+
return Promise.resolve({ done: () => { } });
|
|
56
|
+
}
|
|
57
|
+
// dedupe
|
|
58
|
+
if (this.requestMap.has(handle)) {
|
|
59
|
+
return this.requestMap.get(handle);
|
|
60
|
+
}
|
|
61
|
+
const request = { handle, priority: 0, getPriority };
|
|
62
|
+
const promise = new Promise((resolve) => {
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
request.resolve = resolve;
|
|
65
|
+
return request;
|
|
66
|
+
});
|
|
67
|
+
this.requestQueue.push(request);
|
|
68
|
+
this.requestMap.set(handle, promise);
|
|
81
69
|
this._issueNewRequests();
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
70
|
+
return promise;
|
|
71
|
+
}
|
|
72
|
+
// PRIVATE
|
|
73
|
+
_issueRequest(request) {
|
|
74
|
+
const { handle, resolve } = request;
|
|
75
|
+
let isDone = false;
|
|
76
|
+
const done = () => {
|
|
77
|
+
// can only be called once
|
|
78
|
+
if (!isDone) {
|
|
79
|
+
isDone = true;
|
|
80
|
+
// Stop tracking a request - it has completed, failed, cancelled etc
|
|
81
|
+
this.requestMap.delete(handle);
|
|
82
|
+
this.activeRequestCount--;
|
|
83
|
+
// A slot just freed up, see if any queued requests are waiting
|
|
84
|
+
this._issueNewRequests();
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
// Track this request
|
|
88
|
+
this.activeRequestCount++;
|
|
89
|
+
return resolve ? resolve({ done }) : Promise.resolve({ done });
|
|
96
90
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (freeSlots === 0) {
|
|
104
|
-
return;
|
|
91
|
+
/** We check requests asynchronously, to prevent multiple updates */
|
|
92
|
+
_issueNewRequests() {
|
|
93
|
+
if (!this.deferredUpdate) {
|
|
94
|
+
this.deferredUpdate = setTimeout(() => this._issueNewRequestsAsync(), 0);
|
|
95
|
+
}
|
|
105
96
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
97
|
+
/** Refresh all requests */
|
|
98
|
+
_issueNewRequestsAsync() {
|
|
99
|
+
// TODO - shouldn't we clear the timeout?
|
|
100
|
+
this.deferredUpdate = null;
|
|
101
|
+
const freeSlots = Math.max(this.props.maxRequests - this.activeRequestCount, 0);
|
|
102
|
+
if (freeSlots === 0) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
this._updateAllRequests();
|
|
106
|
+
// Resolve pending promises for the top-priority requests
|
|
107
|
+
for (let i = 0; i < freeSlots; ++i) {
|
|
108
|
+
const request = this.requestQueue.shift();
|
|
109
|
+
if (request) {
|
|
110
|
+
this._issueRequest(request); // eslint-disable-line @typescript-eslint/no-floating-promises
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// Uncomment to debug
|
|
114
|
+
// console.log(`${freeSlots} free slots, ${this.requestQueue.length} queued requests`);
|
|
115
115
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
116
|
+
/** Ensure all requests have updated priorities, and that no longer valid requests are cancelled */
|
|
117
|
+
_updateAllRequests() {
|
|
118
|
+
const requestQueue = this.requestQueue;
|
|
119
|
+
for (let i = 0; i < requestQueue.length; ++i) {
|
|
120
|
+
const request = requestQueue[i];
|
|
121
|
+
if (!this._updateRequest(request)) {
|
|
122
|
+
// Remove the element and make sure to adjust the counter to account for shortened array
|
|
123
|
+
requestQueue.splice(i, 1);
|
|
124
|
+
this.requestMap.delete(request.handle);
|
|
125
|
+
i--;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// Sort the remaining requests based on priority
|
|
129
|
+
requestQueue.sort((a, b) => a.priority - b.priority);
|
|
129
130
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return false;
|
|
131
|
+
/** Update a single request by calling the callback */
|
|
132
|
+
_updateRequest(request) {
|
|
133
|
+
request.priority = request.getPriority(request.handle); // eslint-disable-line callback-return
|
|
134
|
+
// by returning a negative priority, the callback cancels the request
|
|
135
|
+
if (request.priority < 0) {
|
|
136
|
+
request.resolve(null);
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
return true;
|
|
140
140
|
}
|
|
141
|
-
|
|
142
|
-
return true;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
141
|
}
|
|
146
|
-
|
|
142
|
+
exports.default = RequestScheduler;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { LoaderWithParser } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Set up a WebWorkerGlobalScope to talk with the main thread
|
|
4
|
+
* @param loader
|
|
5
|
+
*/
|
|
6
|
+
export declare function createLoaderWorker(loader: LoaderWithParser): void;
|
|
7
|
+
//# sourceMappingURL=create-loader-worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-loader-worker.d.ts","sourceRoot":"","sources":["../../../src/lib/worker-loader-utils/create-loader-worker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,aAAa,CAAC;AAMlD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,gBAAgB,QAgC1D"}
|
|
@@ -1,102 +1,98 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLoaderWorker = void 0;
|
|
4
|
+
const worker_utils_1 = require("@loaders.gl/worker-utils");
|
|
5
|
+
// import {validateLoaderVersion} from './validate-loader-version';
|
|
2
6
|
let requestId = 0;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
try {
|
|
12
|
-
const {
|
|
13
|
-
input,
|
|
14
|
-
options = {}
|
|
15
|
-
} = payload;
|
|
16
|
-
const result = await parseData({
|
|
17
|
-
loader,
|
|
18
|
-
arrayBuffer: input,
|
|
19
|
-
options,
|
|
20
|
-
context: {
|
|
21
|
-
parse: parseOnMainThread
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
WorkerBody.postMessage('done', {
|
|
25
|
-
result
|
|
26
|
-
});
|
|
27
|
-
} catch (error) {
|
|
28
|
-
const message = error instanceof Error ? error.message : '';
|
|
29
|
-
WorkerBody.postMessage('error', {
|
|
30
|
-
error: message
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
break;
|
|
35
|
-
|
|
36
|
-
default:
|
|
7
|
+
/**
|
|
8
|
+
* Set up a WebWorkerGlobalScope to talk with the main thread
|
|
9
|
+
* @param loader
|
|
10
|
+
*/
|
|
11
|
+
function createLoaderWorker(loader) {
|
|
12
|
+
// Check that we are actually in a worker thread
|
|
13
|
+
if (!worker_utils_1.WorkerBody.inWorkerThread()) {
|
|
14
|
+
return;
|
|
37
15
|
}
|
|
38
|
-
|
|
16
|
+
worker_utils_1.WorkerBody.onmessage = async (type, payload) => {
|
|
17
|
+
switch (type) {
|
|
18
|
+
case 'process':
|
|
19
|
+
try {
|
|
20
|
+
// validateLoaderVersion(loader, data.source.split('@')[1]);
|
|
21
|
+
const { input, options = {}, context = {} } = payload;
|
|
22
|
+
const result = await parseData({
|
|
23
|
+
loader,
|
|
24
|
+
arrayBuffer: input,
|
|
25
|
+
options,
|
|
26
|
+
context: {
|
|
27
|
+
...context,
|
|
28
|
+
parse: parseOnMainThread
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
worker_utils_1.WorkerBody.postMessage('done', { result });
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
const message = error instanceof Error ? error.message : '';
|
|
35
|
+
worker_utils_1.WorkerBody.postMessage('error', { error: message });
|
|
36
|
+
}
|
|
37
|
+
break;
|
|
38
|
+
default:
|
|
39
|
+
}
|
|
40
|
+
};
|
|
39
41
|
}
|
|
40
|
-
|
|
42
|
+
exports.createLoaderWorker = createLoaderWorker;
|
|
41
43
|
function parseOnMainThread(arrayBuffer, options) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
options
|
|
70
|
-
};
|
|
71
|
-
WorkerBody.postMessage('process', payload);
|
|
72
|
-
});
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
const id = requestId++;
|
|
46
|
+
/**
|
|
47
|
+
*/
|
|
48
|
+
const onMessage = (type, payload) => {
|
|
49
|
+
if (payload.id !== id) {
|
|
50
|
+
// not ours
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
switch (type) {
|
|
54
|
+
case 'done':
|
|
55
|
+
worker_utils_1.WorkerBody.removeEventListener(onMessage);
|
|
56
|
+
resolve(payload.result);
|
|
57
|
+
break;
|
|
58
|
+
case 'error':
|
|
59
|
+
worker_utils_1.WorkerBody.removeEventListener(onMessage);
|
|
60
|
+
reject(payload.error);
|
|
61
|
+
break;
|
|
62
|
+
default:
|
|
63
|
+
// ignore
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
worker_utils_1.WorkerBody.addEventListener(onMessage);
|
|
67
|
+
// Ask the main thread to decode data
|
|
68
|
+
const payload = { id, input: arrayBuffer, options };
|
|
69
|
+
worker_utils_1.WorkerBody.postMessage('process', payload);
|
|
70
|
+
});
|
|
73
71
|
}
|
|
74
|
-
|
|
75
|
-
async
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}, context, loader);
|
|
72
|
+
// TODO - Support byteOffset and byteLength (enabling parsing of embedded binaries without copies)
|
|
73
|
+
// TODO - Why not support async loader.parse* funcs here?
|
|
74
|
+
// TODO - Why not reuse a common function instead of reimplementing loader.parse* selection logic? Keeping loader small?
|
|
75
|
+
// TODO - Lack of appropriate parser functions can be detected when we create worker, no need to wait until parse
|
|
76
|
+
async function parseData({ loader, arrayBuffer, options, context }) {
|
|
77
|
+
let data;
|
|
78
|
+
let parser;
|
|
79
|
+
if (loader.parseSync || loader.parse) {
|
|
80
|
+
data = arrayBuffer;
|
|
81
|
+
parser = loader.parseSync || loader.parse;
|
|
82
|
+
}
|
|
83
|
+
else if (loader.parseTextSync) {
|
|
84
|
+
const textDecoder = new TextDecoder();
|
|
85
|
+
data = textDecoder.decode(arrayBuffer);
|
|
86
|
+
parser = loader.parseTextSync;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
throw new Error(`Could not load data with ${loader.name} loader`);
|
|
90
|
+
}
|
|
91
|
+
// TODO - proper merge in of loader options...
|
|
92
|
+
options = {
|
|
93
|
+
...options,
|
|
94
|
+
modules: (loader && loader.options && loader.options.modules) || {},
|
|
95
|
+
worker: false
|
|
96
|
+
};
|
|
97
|
+
return await parser(data, { ...options }, context, loader);
|
|
101
98
|
}
|
|
102
|
-
//# sourceMappingURL=create-loader-worker.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Writer, WriterOptions } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Determines if a loader can parse with worker
|
|
4
|
+
* @param loader
|
|
5
|
+
* @param options
|
|
6
|
+
*/
|
|
7
|
+
export declare function canEncodeWithWorker(writer: Writer, options?: WriterOptions): any;
|
|
8
|
+
//# sourceMappingURL=encode-with-worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode-with-worker.d.ts","sourceRoot":"","sources":["../../../src/lib/worker-loader-utils/encode-with-worker.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,aAAa,CAAC;AAGlD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,OAW1E"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.canEncodeWithWorker = void 0;
|
|
4
|
+
const worker_utils_1 = require("@loaders.gl/worker-utils");
|
|
5
|
+
const globals_1 = require("../env-utils/globals");
|
|
6
|
+
/**
|
|
7
|
+
* Determines if a loader can parse with worker
|
|
8
|
+
* @param loader
|
|
9
|
+
* @param options
|
|
10
|
+
*/
|
|
11
|
+
function canEncodeWithWorker(writer, options) {
|
|
12
|
+
if (!worker_utils_1.WorkerFarm.isSupported()) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
// Node workers are still experimental
|
|
16
|
+
if (!globals_1.isBrowser && !options?._nodeWorkers) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return writer.worker && options?.worker;
|
|
20
|
+
}
|
|
21
|
+
exports.canEncodeWithWorker = canEncodeWithWorker;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Loader, LoaderOptions, LoaderContext } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Determines if a loader can parse with worker
|
|
4
|
+
* @param loader
|
|
5
|
+
* @param options
|
|
6
|
+
*/
|
|
7
|
+
export declare function canParseWithWorker(loader: Loader, options?: LoaderOptions): boolean | "" | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* this function expects that the worker function sends certain messages,
|
|
10
|
+
* this can be automated if the worker is wrapper by a call to createLoaderWorker in @loaders.gl/loader-utils.
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseWithWorker(loader: Loader, data: any, options?: LoaderOptions, context?: LoaderContext, parseOnMainThread?: (arrayBuffer: ArrayBuffer, options: {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}) => Promise<void>): Promise<any>;
|
|
15
|
+
//# sourceMappingURL=parse-with-worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-with-worker.d.ts","sourceRoot":"","sources":["../../../src/lib/worker-loader-utils/parse-with-worker.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAE,aAAa,EAAC,MAAM,aAAa,CAAC;AAGtE;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,4BAWzE;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,GAAG,EACT,OAAO,CAAC,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,aAAa,EACvB,iBAAiB,CAAC,EAAE,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,gBA8B/F"}
|