@dxos/async 0.8.4-main.ae835ea → 0.8.4-main.bc2380dfbc
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/LICENSE +102 -5
- package/dist/lib/browser/index.mjs +138 -96
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +138 -96
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/callback.d.ts.map +1 -1
- package/dist/types/src/chain.d.ts.map +1 -1
- package/dist/types/src/cleanup.d.ts +2 -2
- package/dist/types/src/cleanup.d.ts.map +1 -1
- package/dist/types/src/debounce.d.ts +29 -9
- package/dist/types/src/debounce.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/event-emitter.d.ts.map +1 -1
- package/dist/types/src/events.d.ts.map +1 -1
- package/dist/types/src/mutex.d.ts.map +1 -1
- package/dist/types/src/observable-value.d.ts.map +1 -1
- package/dist/types/src/observable.d.ts.map +1 -1
- package/dist/types/src/persistent-lifecycle.d.ts +2 -2
- package/dist/types/src/persistent-lifecycle.d.ts.map +1 -1
- package/dist/types/src/stream-to-array.d.ts.map +1 -1
- package/dist/types/src/task-scheduling.d.ts +29 -1
- package/dist/types/src/task-scheduling.d.ts.map +1 -1
- package/dist/types/src/test-stream.d.ts.map +1 -1
- package/dist/types/src/testing.d.ts.map +1 -1
- package/dist/types/src/timeout.d.ts +1 -1
- package/dist/types/src/timeout.d.ts.map +1 -1
- package/dist/types/src/timer.d.ts.map +1 -1
- package/dist/types/src/track-leaks.d.ts.map +1 -1
- package/dist/types/src/trigger.d.ts.map +1 -1
- package/dist/types/src/update-scheduler.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -11
- package/src/cleanup.ts +7 -4
- package/src/debounce.ts +69 -16
- package/src/event-emitter.test.ts +0 -1
- package/src/observable-value.ts +4 -2
- package/src/persistent-lifecycle.ts +10 -2
- package/src/task-scheduling.ts +95 -1
- package/src/timeout.ts +6 -9
package/LICENSE
CHANGED
|
@@ -1,8 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
Copyright (c) 2022 DXOS
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
## Abbreviation
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 DXOS
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
93
|
+
will apply:
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
96
|
+
this file except in compliance with the License.
|
|
97
|
+
|
|
98
|
+
You may obtain a copy of the License at
|
|
99
|
+
|
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
+
|
|
102
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
103
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
|
+
specific language governing permissions and limitations under the License.
|
|
@@ -22,7 +22,7 @@ var chain = (chain2) => async (elements) => {
|
|
|
22
22
|
import { ComplexMap } from "@dxos/util";
|
|
23
23
|
var combine = (...cleanupFns) => {
|
|
24
24
|
return () => {
|
|
25
|
-
cleanupFns.flat().forEach((cleanupFn) => cleanupFn());
|
|
25
|
+
cleanupFns.flat().filter((f) => typeof f === "function").forEach((cleanupFn) => cleanupFn());
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
var timeout = (cb, ms = 0) => {
|
|
@@ -39,8 +39,8 @@ var addEventListener = (target, type, listener, options) => {
|
|
|
39
39
|
};
|
|
40
40
|
var SubscriptionList = class {
|
|
41
41
|
_cleanups = [];
|
|
42
|
-
add(cb) {
|
|
43
|
-
this._cleanups.push(cb);
|
|
42
|
+
add(...cb) {
|
|
43
|
+
this._cleanups.push(...cb);
|
|
44
44
|
return this;
|
|
45
45
|
}
|
|
46
46
|
clear() {
|
|
@@ -64,29 +64,55 @@ var SubscriptionSet = class {
|
|
|
64
64
|
};
|
|
65
65
|
|
|
66
66
|
// src/debounce.ts
|
|
67
|
-
var
|
|
67
|
+
var delay = (cb, delay2 = 100) => {
|
|
68
|
+
let pending = false;
|
|
69
|
+
return (...args) => {
|
|
70
|
+
if (pending) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
pending = true;
|
|
74
|
+
setTimeout(() => {
|
|
75
|
+
try {
|
|
76
|
+
cb(...args);
|
|
77
|
+
} finally {
|
|
78
|
+
pending = false;
|
|
79
|
+
}
|
|
80
|
+
}, delay2);
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
var debounce = (cb, delay2 = 100) => {
|
|
68
84
|
let t;
|
|
69
85
|
return (...args) => {
|
|
70
86
|
clearTimeout(t);
|
|
71
|
-
t = setTimeout(() => cb(...args),
|
|
87
|
+
t = setTimeout(() => cb(...args), delay2);
|
|
72
88
|
};
|
|
73
89
|
};
|
|
74
|
-
var throttle = (cb,
|
|
90
|
+
var throttle = (cb, delay2 = 100) => {
|
|
75
91
|
let lastCall = 0;
|
|
76
92
|
return (...args) => {
|
|
77
93
|
const now = Date.now();
|
|
78
|
-
if (now - lastCall >=
|
|
94
|
+
if (now - lastCall >= delay2) {
|
|
79
95
|
cb(...args);
|
|
80
96
|
lastCall = now;
|
|
81
97
|
}
|
|
82
98
|
};
|
|
83
99
|
};
|
|
84
|
-
var debounceAndThrottle = (cb,
|
|
85
|
-
|
|
86
|
-
|
|
100
|
+
var debounceAndThrottle = (cb, delay2 = 100) => {
|
|
101
|
+
let timeout2;
|
|
102
|
+
let lastCall = 0;
|
|
87
103
|
return (...args) => {
|
|
88
|
-
|
|
89
|
-
|
|
104
|
+
const now = Date.now();
|
|
105
|
+
const delta = now - lastCall;
|
|
106
|
+
clearTimeout(timeout2);
|
|
107
|
+
if (delta >= delay2) {
|
|
108
|
+
cb(...args);
|
|
109
|
+
lastCall = now;
|
|
110
|
+
} else {
|
|
111
|
+
timeout2 = setTimeout(() => {
|
|
112
|
+
cb(...args);
|
|
113
|
+
lastCall = Date.now();
|
|
114
|
+
}, delay2 - delta);
|
|
115
|
+
}
|
|
90
116
|
};
|
|
91
117
|
};
|
|
92
118
|
|
|
@@ -140,6 +166,9 @@ var sleepWithContext = (ctx, ms) => {
|
|
|
140
166
|
};
|
|
141
167
|
var asyncReturn = () => sleep(0);
|
|
142
168
|
var asyncTimeout = async (promise, timeout2, err) => {
|
|
169
|
+
if (typeof promise === "function") {
|
|
170
|
+
throw new Error("First argument must be a promise.");
|
|
171
|
+
}
|
|
143
172
|
let timeoutId;
|
|
144
173
|
const throwable = err === void 0 || typeof err === "string" ? new TimeoutError(timeout2, err) : err;
|
|
145
174
|
const timeoutPromise = new Promise((resolve, reject) => {
|
|
@@ -148,9 +177,8 @@ var asyncTimeout = async (promise, timeout2, err) => {
|
|
|
148
177
|
}, timeout2);
|
|
149
178
|
unrefTimeout(timeoutId);
|
|
150
179
|
});
|
|
151
|
-
const conditionTimeout = typeof promise === "function" ? promiseFromCallback(promise) : promise;
|
|
152
180
|
return await Promise.race([
|
|
153
|
-
|
|
181
|
+
promise,
|
|
154
182
|
timeoutPromise
|
|
155
183
|
]).finally(() => {
|
|
156
184
|
clearTimeout(timeoutId);
|
|
@@ -187,7 +215,6 @@ var waitForEvent = (eventEmitter, eventName, test, timeout2, error) => {
|
|
|
187
215
|
|
|
188
216
|
// src/events.ts
|
|
189
217
|
import { Context } from "@dxos/context";
|
|
190
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/common/async/src/events.ts";
|
|
191
218
|
var DO_NOT_ERROR_ON_ASYNC_CALLBACK = true;
|
|
192
219
|
var Event = class _Event {
|
|
193
220
|
/**
|
|
@@ -242,10 +269,7 @@ var Event = class _Event {
|
|
|
242
269
|
_ctx,
|
|
243
270
|
_callback
|
|
244
271
|
] : [
|
|
245
|
-
new Context(
|
|
246
|
-
F: __dxlog_file,
|
|
247
|
-
L: 132
|
|
248
|
-
}),
|
|
272
|
+
new Context(),
|
|
249
273
|
_ctx
|
|
250
274
|
];
|
|
251
275
|
const weak = !!options?.weak;
|
|
@@ -275,10 +299,7 @@ var Event = class _Event {
|
|
|
275
299
|
_ctx,
|
|
276
300
|
_callback
|
|
277
301
|
] : [
|
|
278
|
-
new Context(
|
|
279
|
-
F: __dxlog_file,
|
|
280
|
-
L: 169
|
|
281
|
-
}),
|
|
302
|
+
new Context(),
|
|
282
303
|
_ctx
|
|
283
304
|
];
|
|
284
305
|
const listener = new EventListener(this, callback, ctx, true, false);
|
|
@@ -581,7 +602,7 @@ var MutexGuard = class {
|
|
|
581
602
|
this.release();
|
|
582
603
|
}
|
|
583
604
|
};
|
|
584
|
-
var classMutexSymbol = Symbol("class-mutex");
|
|
605
|
+
var classMutexSymbol = /* @__PURE__ */ Symbol("class-mutex");
|
|
585
606
|
var FORCE_DISABLE_WARNING = false;
|
|
586
607
|
var enableWarning = !FORCE_DISABLE_WARNING && globalThis.mochaExecutor;
|
|
587
608
|
var synchronized = (target, propertyName, descriptor) => {
|
|
@@ -612,7 +633,6 @@ import PushStream from "zen-push";
|
|
|
612
633
|
|
|
613
634
|
// src/trigger.ts
|
|
614
635
|
import { invariant } from "@dxos/invariant";
|
|
615
|
-
var __dxlog_file2 = "/__w/dxos/dxos/packages/common/async/src/trigger.ts";
|
|
616
636
|
var trigger = (timeout2) => {
|
|
617
637
|
let callback;
|
|
618
638
|
const promise = new Promise((resolve, reject) => {
|
|
@@ -704,15 +724,7 @@ var Trigger = class {
|
|
|
704
724
|
}
|
|
705
725
|
};
|
|
706
726
|
var latch = ({ count = 1, timeout: timeout2 } = {}) => {
|
|
707
|
-
invariant(count >= 0
|
|
708
|
-
F: __dxlog_file2,
|
|
709
|
-
L: 139,
|
|
710
|
-
S: void 0,
|
|
711
|
-
A: [
|
|
712
|
-
"count >= 0",
|
|
713
|
-
""
|
|
714
|
-
]
|
|
715
|
-
});
|
|
727
|
+
invariant(count >= 0);
|
|
716
728
|
let t;
|
|
717
729
|
let doResolve;
|
|
718
730
|
let doReject;
|
|
@@ -909,16 +921,15 @@ import { warnAfterTimeout as warnAfterTimeout2 } from "@dxos/debug";
|
|
|
909
921
|
import { log as log2 } from "@dxos/log";
|
|
910
922
|
|
|
911
923
|
// src/task-scheduling.ts
|
|
912
|
-
import { ContextDisposedError as ContextDisposedError2 } from "@dxos/context";
|
|
924
|
+
import { Context as Context2, ContextDisposedError as ContextDisposedError2 } from "@dxos/context";
|
|
913
925
|
import { StackTrace as StackTrace2 } from "@dxos/debug";
|
|
914
926
|
|
|
915
927
|
// src/track-leaks.ts
|
|
916
928
|
import { StackTrace } from "@dxos/debug";
|
|
917
929
|
import { log } from "@dxos/log";
|
|
918
|
-
var __dxlog_file3 = "/__w/dxos/dxos/packages/common/async/src/track-leaks.ts";
|
|
919
930
|
var enabled = typeof process !== "undefined" && !!process.env.DX_TRACK_LEAKS;
|
|
920
931
|
var openResources = /* @__PURE__ */ new Set();
|
|
921
|
-
var handleSymbol = Symbol("checkLeaksHandle");
|
|
932
|
+
var handleSymbol = /* @__PURE__ */ Symbol("checkLeaksHandle");
|
|
922
933
|
var trackResource = (resourceProvider) => {
|
|
923
934
|
if (!enabled) {
|
|
924
935
|
return () => {
|
|
@@ -965,31 +976,11 @@ var dumpLeaks = () => {
|
|
|
965
976
|
if (!enabled) {
|
|
966
977
|
return;
|
|
967
978
|
}
|
|
968
|
-
log.info(`Leaked resources ${openResources.size}
|
|
969
|
-
F: __dxlog_file3,
|
|
970
|
-
L: 82,
|
|
971
|
-
S: void 0,
|
|
972
|
-
C: (f, a) => f(...a)
|
|
973
|
-
});
|
|
979
|
+
log.info(`Leaked resources ${openResources.size}:`);
|
|
974
980
|
for (const resource of openResources) {
|
|
975
|
-
log.info(`- ${resource.name} at
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
S: void 0,
|
|
979
|
-
C: (f, a) => f(...a)
|
|
980
|
-
});
|
|
981
|
-
log.info(resource.openStack.getStack(1), void 0, {
|
|
982
|
-
F: __dxlog_file3,
|
|
983
|
-
L: 85,
|
|
984
|
-
S: void 0,
|
|
985
|
-
C: (f, a) => f(...a)
|
|
986
|
-
});
|
|
987
|
-
log.info("\n", void 0, {
|
|
988
|
-
F: __dxlog_file3,
|
|
989
|
-
L: 86,
|
|
990
|
-
S: void 0,
|
|
991
|
-
C: (f, a) => f(...a)
|
|
992
|
-
});
|
|
981
|
+
log.info(`- ${resource.name} at`);
|
|
982
|
+
log.info(resource.openStack.getStack(1));
|
|
983
|
+
log.info("\n");
|
|
993
984
|
}
|
|
994
985
|
};
|
|
995
986
|
if (enabled) {
|
|
@@ -1046,6 +1037,79 @@ var DeferredTask = class {
|
|
|
1046
1037
|
await this._currentTask;
|
|
1047
1038
|
}
|
|
1048
1039
|
};
|
|
1040
|
+
var AsyncTask = class {
|
|
1041
|
+
#callback;
|
|
1042
|
+
#ctx = void 0;
|
|
1043
|
+
#scheduled = false;
|
|
1044
|
+
#currentTask = null;
|
|
1045
|
+
#nextTask = new Trigger();
|
|
1046
|
+
constructor(callback) {
|
|
1047
|
+
this.#callback = callback;
|
|
1048
|
+
}
|
|
1049
|
+
get scheduled() {
|
|
1050
|
+
return this.#scheduled;
|
|
1051
|
+
}
|
|
1052
|
+
/**
|
|
1053
|
+
* Context of the resource that owns the task.
|
|
1054
|
+
* When the context is disposed, the task is cancelled and cannot be scheduled again.
|
|
1055
|
+
*/
|
|
1056
|
+
open() {
|
|
1057
|
+
this.#ctx = new Context2();
|
|
1058
|
+
}
|
|
1059
|
+
/**
|
|
1060
|
+
* Closes the task and waits for it to finish if it is running.
|
|
1061
|
+
*/
|
|
1062
|
+
async close() {
|
|
1063
|
+
await this.#ctx?.dispose();
|
|
1064
|
+
await this.join();
|
|
1065
|
+
this.#ctx = void 0;
|
|
1066
|
+
}
|
|
1067
|
+
[Symbol.asyncDispose]() {
|
|
1068
|
+
return this.close();
|
|
1069
|
+
}
|
|
1070
|
+
/**
|
|
1071
|
+
* Schedule the task to run asynchronously.
|
|
1072
|
+
*/
|
|
1073
|
+
// TODO(dmaretskyi): Add scheduleAt. Where the earlier time will override the later one.
|
|
1074
|
+
schedule() {
|
|
1075
|
+
if (!this.#ctx || this.#ctx.disposed) {
|
|
1076
|
+
throw new Error("AsyncTask not open");
|
|
1077
|
+
}
|
|
1078
|
+
if (this.#scheduled) {
|
|
1079
|
+
return;
|
|
1080
|
+
}
|
|
1081
|
+
scheduleTask(this.#ctx, async () => {
|
|
1082
|
+
await this.#currentTask;
|
|
1083
|
+
if (!this.#ctx || this.#ctx.disposed) {
|
|
1084
|
+
return;
|
|
1085
|
+
}
|
|
1086
|
+
this.#scheduled = false;
|
|
1087
|
+
const completionTrigger = this.#nextTask;
|
|
1088
|
+
this.#nextTask = new Trigger();
|
|
1089
|
+
this.#currentTask = runInContextAsync(this.#ctx, () => this.#callback()).then(() => {
|
|
1090
|
+
completionTrigger.wake();
|
|
1091
|
+
});
|
|
1092
|
+
});
|
|
1093
|
+
this.#scheduled = true;
|
|
1094
|
+
}
|
|
1095
|
+
/**
|
|
1096
|
+
* Schedule the task to run and wait for it to finish.
|
|
1097
|
+
*/
|
|
1098
|
+
async runBlocking() {
|
|
1099
|
+
if (this.#ctx?.disposed) {
|
|
1100
|
+
throw new ContextDisposedError2();
|
|
1101
|
+
}
|
|
1102
|
+
this.schedule();
|
|
1103
|
+
await this.#nextTask.wait();
|
|
1104
|
+
}
|
|
1105
|
+
/**
|
|
1106
|
+
* Waits for the current task to finish if it is running.
|
|
1107
|
+
* Does not schedule a new task.
|
|
1108
|
+
*/
|
|
1109
|
+
async join() {
|
|
1110
|
+
await this.#currentTask;
|
|
1111
|
+
}
|
|
1112
|
+
};
|
|
1049
1113
|
var runInContext = (ctx, fn) => {
|
|
1050
1114
|
try {
|
|
1051
1115
|
fn();
|
|
@@ -1131,7 +1195,6 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
1131
1195
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1132
1196
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1133
1197
|
}
|
|
1134
|
-
var __dxlog_file4 = "/__w/dxos/dxos/packages/common/async/src/persistent-lifecycle.ts";
|
|
1135
1198
|
var INIT_RESTART_DELAY = 100;
|
|
1136
1199
|
var DEFAULT_MAX_RESTART_DELAY = 5e3;
|
|
1137
1200
|
var PersistentLifecycle = class extends Resource {
|
|
@@ -1157,25 +1220,21 @@ var PersistentLifecycle = class extends Resource {
|
|
|
1157
1220
|
try {
|
|
1158
1221
|
await this._restart();
|
|
1159
1222
|
} catch (err) {
|
|
1223
|
+
if (this._ctx?.disposed) {
|
|
1224
|
+
return;
|
|
1225
|
+
}
|
|
1160
1226
|
log2.warn("Restart failed", {
|
|
1161
1227
|
err
|
|
1162
|
-
}, {
|
|
1163
|
-
F: __dxlog_file4,
|
|
1164
|
-
L: 72,
|
|
1165
|
-
S: this,
|
|
1166
|
-
C: (f, a) => f(...a)
|
|
1167
1228
|
});
|
|
1168
1229
|
this._restartTask?.schedule();
|
|
1169
1230
|
}
|
|
1170
1231
|
});
|
|
1171
1232
|
this._currentState = await this._start().catch((err) => {
|
|
1233
|
+
if (this._ctx?.disposed) {
|
|
1234
|
+
return void 0;
|
|
1235
|
+
}
|
|
1172
1236
|
log2.warn("Start failed", {
|
|
1173
1237
|
err
|
|
1174
|
-
}, {
|
|
1175
|
-
F: __dxlog_file4,
|
|
1176
|
-
L: 78,
|
|
1177
|
-
S: this,
|
|
1178
|
-
C: (f, a) => f(...a)
|
|
1179
1238
|
});
|
|
1180
1239
|
this._restartTask?.schedule();
|
|
1181
1240
|
return void 0;
|
|
@@ -1189,11 +1248,6 @@ var PersistentLifecycle = class extends Resource {
|
|
|
1189
1248
|
async _restart() {
|
|
1190
1249
|
log2(`restarting in ${this._restartAfter}ms`, {
|
|
1191
1250
|
state: this._lifecycleState
|
|
1192
|
-
}, {
|
|
1193
|
-
F: __dxlog_file4,
|
|
1194
|
-
L: 91,
|
|
1195
|
-
S: this,
|
|
1196
|
-
C: (f, a) => f(...a)
|
|
1197
1251
|
});
|
|
1198
1252
|
await this._stopCurrentState();
|
|
1199
1253
|
if (this._lifecycleState !== LifecycleState.OPEN) {
|
|
@@ -1212,12 +1266,7 @@ var PersistentLifecycle = class extends Resource {
|
|
|
1212
1266
|
try {
|
|
1213
1267
|
await this._stop(this._currentState);
|
|
1214
1268
|
} catch (err) {
|
|
1215
|
-
log2.catch(err
|
|
1216
|
-
F: __dxlog_file4,
|
|
1217
|
-
L: 113,
|
|
1218
|
-
S: this,
|
|
1219
|
-
C: (f, a) => f(...a)
|
|
1220
|
-
});
|
|
1269
|
+
log2.catch(err);
|
|
1221
1270
|
}
|
|
1222
1271
|
this._currentState = void 0;
|
|
1223
1272
|
}
|
|
@@ -1241,7 +1290,6 @@ _ts_decorate([
|
|
|
1241
1290
|
|
|
1242
1291
|
// src/push-iterable.ts
|
|
1243
1292
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
1244
|
-
var __dxlog_file5 = "/__w/dxos/dxos/packages/common/async/src/push-iterable.ts";
|
|
1245
1293
|
var makePushIterable = () => {
|
|
1246
1294
|
const buf = [];
|
|
1247
1295
|
const trigger2 = new Trigger({
|
|
@@ -1255,15 +1303,7 @@ var makePushIterable = () => {
|
|
|
1255
1303
|
await trigger2.wait();
|
|
1256
1304
|
}
|
|
1257
1305
|
const item = buf.shift();
|
|
1258
|
-
invariant2(item
|
|
1259
|
-
F: __dxlog_file5,
|
|
1260
|
-
L: 42,
|
|
1261
|
-
S: this,
|
|
1262
|
-
A: [
|
|
1263
|
-
"item",
|
|
1264
|
-
""
|
|
1265
|
-
]
|
|
1266
|
-
});
|
|
1306
|
+
invariant2(item);
|
|
1267
1307
|
switch (item.kind) {
|
|
1268
1308
|
case "next":
|
|
1269
1309
|
return {
|
|
@@ -1518,13 +1558,13 @@ var UpdateScheduler = class {
|
|
|
1518
1558
|
await this._promise;
|
|
1519
1559
|
if (this._params.maxFrequency) {
|
|
1520
1560
|
const now = performance.now();
|
|
1521
|
-
const
|
|
1522
|
-
if (
|
|
1561
|
+
const delay2 = this._lastUpdateTime + TIME_PERIOD / this._params.maxFrequency - now;
|
|
1562
|
+
if (delay2 > 0) {
|
|
1523
1563
|
await new Promise((resolve) => {
|
|
1524
1564
|
const timeoutId = setTimeout(() => {
|
|
1525
1565
|
clearContext();
|
|
1526
1566
|
resolve();
|
|
1527
|
-
},
|
|
1567
|
+
}, delay2);
|
|
1528
1568
|
const clearContext = this._ctx.onDispose(() => {
|
|
1529
1569
|
clearTimeout(timeoutId);
|
|
1530
1570
|
resolve();
|
|
@@ -1568,6 +1608,7 @@ var UpdateScheduler = class {
|
|
|
1568
1608
|
}
|
|
1569
1609
|
};
|
|
1570
1610
|
export {
|
|
1611
|
+
AsyncTask,
|
|
1571
1612
|
CancellableObservableProvider,
|
|
1572
1613
|
DeferredTask,
|
|
1573
1614
|
Event,
|
|
@@ -1594,6 +1635,7 @@ export {
|
|
|
1594
1635
|
combine,
|
|
1595
1636
|
debounce,
|
|
1596
1637
|
debounceAndThrottle,
|
|
1638
|
+
delay,
|
|
1597
1639
|
dumpLeaks,
|
|
1598
1640
|
interval,
|
|
1599
1641
|
latch,
|