@dxos/async 0.8.4-main.ef1bc66f44 → 0.8.4-main.effb148878
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 +23 -86
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +23 -86
- 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 +1 -2
- package/dist/types/src/cleanup.d.ts.map +1 -1
- package/dist/types/src/debounce.d.ts +15 -10
- 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.map +1 -1
- package/dist/types/src/stream-to-array.d.ts.map +1 -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 +8 -11
- package/src/cleanup.ts +5 -3
- package/src/debounce.ts +19 -14
- package/src/event-emitter.test.ts +0 -1
- package/src/observable-value.ts +4 -2
- package/src/persistent-lifecycle.ts +8 -0
- 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) => {
|
|
@@ -166,6 +166,9 @@ var sleepWithContext = (ctx, ms) => {
|
|
|
166
166
|
};
|
|
167
167
|
var asyncReturn = () => sleep(0);
|
|
168
168
|
var asyncTimeout = async (promise, timeout2, err) => {
|
|
169
|
+
if (typeof promise === "function") {
|
|
170
|
+
throw new Error("First argument must be a promise.");
|
|
171
|
+
}
|
|
169
172
|
let timeoutId;
|
|
170
173
|
const throwable = err === void 0 || typeof err === "string" ? new TimeoutError(timeout2, err) : err;
|
|
171
174
|
const timeoutPromise = new Promise((resolve, reject) => {
|
|
@@ -174,9 +177,8 @@ var asyncTimeout = async (promise, timeout2, err) => {
|
|
|
174
177
|
}, timeout2);
|
|
175
178
|
unrefTimeout(timeoutId);
|
|
176
179
|
});
|
|
177
|
-
const conditionTimeout = typeof promise === "function" ? promiseFromCallback(promise) : promise;
|
|
178
180
|
return await Promise.race([
|
|
179
|
-
|
|
181
|
+
promise,
|
|
180
182
|
timeoutPromise
|
|
181
183
|
]).finally(() => {
|
|
182
184
|
clearTimeout(timeoutId);
|
|
@@ -213,7 +215,6 @@ var waitForEvent = (eventEmitter, eventName, test, timeout2, error) => {
|
|
|
213
215
|
|
|
214
216
|
// src/events.ts
|
|
215
217
|
import { Context } from "@dxos/context";
|
|
216
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/common/async/src/events.ts";
|
|
217
218
|
var DO_NOT_ERROR_ON_ASYNC_CALLBACK = true;
|
|
218
219
|
var Event = class _Event {
|
|
219
220
|
/**
|
|
@@ -268,10 +269,7 @@ var Event = class _Event {
|
|
|
268
269
|
_ctx,
|
|
269
270
|
_callback
|
|
270
271
|
] : [
|
|
271
|
-
new Context(
|
|
272
|
-
F: __dxlog_file,
|
|
273
|
-
L: 132
|
|
274
|
-
}),
|
|
272
|
+
new Context(),
|
|
275
273
|
_ctx
|
|
276
274
|
];
|
|
277
275
|
const weak = !!options?.weak;
|
|
@@ -301,10 +299,7 @@ var Event = class _Event {
|
|
|
301
299
|
_ctx,
|
|
302
300
|
_callback
|
|
303
301
|
] : [
|
|
304
|
-
new Context(
|
|
305
|
-
F: __dxlog_file,
|
|
306
|
-
L: 169
|
|
307
|
-
}),
|
|
302
|
+
new Context(),
|
|
308
303
|
_ctx
|
|
309
304
|
];
|
|
310
305
|
const listener = new EventListener(this, callback, ctx, true, false);
|
|
@@ -607,7 +602,7 @@ var MutexGuard = class {
|
|
|
607
602
|
this.release();
|
|
608
603
|
}
|
|
609
604
|
};
|
|
610
|
-
var classMutexSymbol = Symbol("class-mutex");
|
|
605
|
+
var classMutexSymbol = /* @__PURE__ */ Symbol("class-mutex");
|
|
611
606
|
var FORCE_DISABLE_WARNING = false;
|
|
612
607
|
var enableWarning = !FORCE_DISABLE_WARNING && globalThis.mochaExecutor;
|
|
613
608
|
var synchronized = (target, propertyName, descriptor) => {
|
|
@@ -638,7 +633,6 @@ import PushStream from "zen-push";
|
|
|
638
633
|
|
|
639
634
|
// src/trigger.ts
|
|
640
635
|
import { invariant } from "@dxos/invariant";
|
|
641
|
-
var __dxlog_file2 = "/__w/dxos/dxos/packages/common/async/src/trigger.ts";
|
|
642
636
|
var trigger = (timeout2) => {
|
|
643
637
|
let callback;
|
|
644
638
|
const promise = new Promise((resolve, reject) => {
|
|
@@ -730,15 +724,7 @@ var Trigger = class {
|
|
|
730
724
|
}
|
|
731
725
|
};
|
|
732
726
|
var latch = ({ count = 1, timeout: timeout2 } = {}) => {
|
|
733
|
-
invariant(count >= 0
|
|
734
|
-
F: __dxlog_file2,
|
|
735
|
-
L: 139,
|
|
736
|
-
S: void 0,
|
|
737
|
-
A: [
|
|
738
|
-
"count >= 0",
|
|
739
|
-
""
|
|
740
|
-
]
|
|
741
|
-
});
|
|
727
|
+
invariant(count >= 0);
|
|
742
728
|
let t;
|
|
743
729
|
let doResolve;
|
|
744
730
|
let doReject;
|
|
@@ -941,10 +927,9 @@ import { StackTrace as StackTrace2 } from "@dxos/debug";
|
|
|
941
927
|
// src/track-leaks.ts
|
|
942
928
|
import { StackTrace } from "@dxos/debug";
|
|
943
929
|
import { log } from "@dxos/log";
|
|
944
|
-
var __dxlog_file3 = "/__w/dxos/dxos/packages/common/async/src/track-leaks.ts";
|
|
945
930
|
var enabled = typeof process !== "undefined" && !!process.env.DX_TRACK_LEAKS;
|
|
946
931
|
var openResources = /* @__PURE__ */ new Set();
|
|
947
|
-
var handleSymbol = Symbol("checkLeaksHandle");
|
|
932
|
+
var handleSymbol = /* @__PURE__ */ Symbol("checkLeaksHandle");
|
|
948
933
|
var trackResource = (resourceProvider) => {
|
|
949
934
|
if (!enabled) {
|
|
950
935
|
return () => {
|
|
@@ -991,31 +976,11 @@ var dumpLeaks = () => {
|
|
|
991
976
|
if (!enabled) {
|
|
992
977
|
return;
|
|
993
978
|
}
|
|
994
|
-
log.info(`Leaked resources ${openResources.size}
|
|
995
|
-
F: __dxlog_file3,
|
|
996
|
-
L: 82,
|
|
997
|
-
S: void 0,
|
|
998
|
-
C: (f, a) => f(...a)
|
|
999
|
-
});
|
|
979
|
+
log.info(`Leaked resources ${openResources.size}:`);
|
|
1000
980
|
for (const resource of openResources) {
|
|
1001
|
-
log.info(`- ${resource.name} at
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
S: void 0,
|
|
1005
|
-
C: (f, a) => f(...a)
|
|
1006
|
-
});
|
|
1007
|
-
log.info(resource.openStack.getStack(1), void 0, {
|
|
1008
|
-
F: __dxlog_file3,
|
|
1009
|
-
L: 85,
|
|
1010
|
-
S: void 0,
|
|
1011
|
-
C: (f, a) => f(...a)
|
|
1012
|
-
});
|
|
1013
|
-
log.info("\n", void 0, {
|
|
1014
|
-
F: __dxlog_file3,
|
|
1015
|
-
L: 86,
|
|
1016
|
-
S: void 0,
|
|
1017
|
-
C: (f, a) => f(...a)
|
|
1018
|
-
});
|
|
981
|
+
log.info(`- ${resource.name} at`);
|
|
982
|
+
log.info(resource.openStack.getStack(1));
|
|
983
|
+
log.info("\n");
|
|
1019
984
|
}
|
|
1020
985
|
};
|
|
1021
986
|
if (enabled) {
|
|
@@ -1023,7 +988,6 @@ if (enabled) {
|
|
|
1023
988
|
}
|
|
1024
989
|
|
|
1025
990
|
// src/task-scheduling.ts
|
|
1026
|
-
var __dxlog_file4 = "/__w/dxos/dxos/packages/common/async/src/task-scheduling.ts";
|
|
1027
991
|
var DeferredTask = class {
|
|
1028
992
|
_ctx;
|
|
1029
993
|
_callback;
|
|
@@ -1090,10 +1054,7 @@ var AsyncTask = class {
|
|
|
1090
1054
|
* When the context is disposed, the task is cancelled and cannot be scheduled again.
|
|
1091
1055
|
*/
|
|
1092
1056
|
open() {
|
|
1093
|
-
this.#ctx = new Context2(
|
|
1094
|
-
F: __dxlog_file4,
|
|
1095
|
-
L: 102
|
|
1096
|
-
});
|
|
1057
|
+
this.#ctx = new Context2();
|
|
1097
1058
|
}
|
|
1098
1059
|
/**
|
|
1099
1060
|
* Closes the task and waits for it to finish if it is running.
|
|
@@ -1234,7 +1195,6 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
1234
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;
|
|
1235
1196
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1236
1197
|
}
|
|
1237
|
-
var __dxlog_file5 = "/__w/dxos/dxos/packages/common/async/src/persistent-lifecycle.ts";
|
|
1238
1198
|
var INIT_RESTART_DELAY = 100;
|
|
1239
1199
|
var DEFAULT_MAX_RESTART_DELAY = 5e3;
|
|
1240
1200
|
var PersistentLifecycle = class extends Resource {
|
|
@@ -1260,25 +1220,21 @@ var PersistentLifecycle = class extends Resource {
|
|
|
1260
1220
|
try {
|
|
1261
1221
|
await this._restart();
|
|
1262
1222
|
} catch (err) {
|
|
1223
|
+
if (this._ctx?.disposed) {
|
|
1224
|
+
return;
|
|
1225
|
+
}
|
|
1263
1226
|
log2.warn("Restart failed", {
|
|
1264
1227
|
err
|
|
1265
|
-
}, {
|
|
1266
|
-
F: __dxlog_file5,
|
|
1267
|
-
L: 72,
|
|
1268
|
-
S: this,
|
|
1269
|
-
C: (f, a) => f(...a)
|
|
1270
1228
|
});
|
|
1271
1229
|
this._restartTask?.schedule();
|
|
1272
1230
|
}
|
|
1273
1231
|
});
|
|
1274
1232
|
this._currentState = await this._start().catch((err) => {
|
|
1233
|
+
if (this._ctx?.disposed) {
|
|
1234
|
+
return void 0;
|
|
1235
|
+
}
|
|
1275
1236
|
log2.warn("Start failed", {
|
|
1276
1237
|
err
|
|
1277
|
-
}, {
|
|
1278
|
-
F: __dxlog_file5,
|
|
1279
|
-
L: 78,
|
|
1280
|
-
S: this,
|
|
1281
|
-
C: (f, a) => f(...a)
|
|
1282
1238
|
});
|
|
1283
1239
|
this._restartTask?.schedule();
|
|
1284
1240
|
return void 0;
|
|
@@ -1292,11 +1248,6 @@ var PersistentLifecycle = class extends Resource {
|
|
|
1292
1248
|
async _restart() {
|
|
1293
1249
|
log2(`restarting in ${this._restartAfter}ms`, {
|
|
1294
1250
|
state: this._lifecycleState
|
|
1295
|
-
}, {
|
|
1296
|
-
F: __dxlog_file5,
|
|
1297
|
-
L: 91,
|
|
1298
|
-
S: this,
|
|
1299
|
-
C: (f, a) => f(...a)
|
|
1300
1251
|
});
|
|
1301
1252
|
await this._stopCurrentState();
|
|
1302
1253
|
if (this._lifecycleState !== LifecycleState.OPEN) {
|
|
@@ -1315,12 +1266,7 @@ var PersistentLifecycle = class extends Resource {
|
|
|
1315
1266
|
try {
|
|
1316
1267
|
await this._stop(this._currentState);
|
|
1317
1268
|
} catch (err) {
|
|
1318
|
-
log2.catch(err
|
|
1319
|
-
F: __dxlog_file5,
|
|
1320
|
-
L: 113,
|
|
1321
|
-
S: this,
|
|
1322
|
-
C: (f, a) => f(...a)
|
|
1323
|
-
});
|
|
1269
|
+
log2.catch(err);
|
|
1324
1270
|
}
|
|
1325
1271
|
this._currentState = void 0;
|
|
1326
1272
|
}
|
|
@@ -1344,7 +1290,6 @@ _ts_decorate([
|
|
|
1344
1290
|
|
|
1345
1291
|
// src/push-iterable.ts
|
|
1346
1292
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
1347
|
-
var __dxlog_file6 = "/__w/dxos/dxos/packages/common/async/src/push-iterable.ts";
|
|
1348
1293
|
var makePushIterable = () => {
|
|
1349
1294
|
const buf = [];
|
|
1350
1295
|
const trigger2 = new Trigger({
|
|
@@ -1358,15 +1303,7 @@ var makePushIterable = () => {
|
|
|
1358
1303
|
await trigger2.wait();
|
|
1359
1304
|
}
|
|
1360
1305
|
const item = buf.shift();
|
|
1361
|
-
invariant2(item
|
|
1362
|
-
F: __dxlog_file6,
|
|
1363
|
-
L: 42,
|
|
1364
|
-
S: this,
|
|
1365
|
-
A: [
|
|
1366
|
-
"item",
|
|
1367
|
-
""
|
|
1368
|
-
]
|
|
1369
|
-
});
|
|
1306
|
+
invariant2(item);
|
|
1370
1307
|
switch (item.kind) {
|
|
1371
1308
|
case "next":
|
|
1372
1309
|
return {
|