opus-codec-worker 0.0.32 → 0.0.34
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/actions/Client.js +11 -0
- package/package.json +1 -1
package/actions/Client.js
CHANGED
|
@@ -17,6 +17,7 @@ class Client {
|
|
|
17
17
|
close() {
|
|
18
18
|
this.#worker.terminate();
|
|
19
19
|
for (const p of this.#pending) {
|
|
20
|
+
this.#pending.delete(p[0]);
|
|
20
21
|
p[1]({
|
|
21
22
|
requestId: p[0],
|
|
22
23
|
failures: ['Worker destroyed'],
|
|
@@ -24,12 +25,22 @@ class Client {
|
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
sendMessage(data) {
|
|
28
|
+
const waitTimeBeforeResolvingAutomaticallyInMilliseconds = 10000;
|
|
27
29
|
return new Promise((resolve, reject) => {
|
|
28
30
|
if (this.#pending.has(data.requestId)) {
|
|
29
31
|
reject(new Error(`Request already exists: ${data.requestId}`));
|
|
30
32
|
return;
|
|
31
33
|
}
|
|
34
|
+
const timeoutId = setTimeout(() => {
|
|
35
|
+
resolve({
|
|
36
|
+
requestId: data.requestId,
|
|
37
|
+
failures: [
|
|
38
|
+
`Timeout expired. It took more than ${waitTimeBeforeResolvingAutomaticallyInMilliseconds} to resolve this request.`,
|
|
39
|
+
],
|
|
40
|
+
});
|
|
41
|
+
}, waitTimeBeforeResolvingAutomaticallyInMilliseconds);
|
|
32
42
|
this.#pending.set(data.requestId, (data) => {
|
|
43
|
+
clearTimeout(timeoutId);
|
|
33
44
|
resolve(data);
|
|
34
45
|
});
|
|
35
46
|
this.#worker.postMessage(data);
|