@evolu/common 8.0.0-next.3 → 8.0.0-next.5
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/src/Assert.d.ts +10 -5
- package/dist/src/Assert.d.ts.map +1 -1
- package/dist/src/Assert.js +10 -5
- package/dist/src/Error.d.ts +5 -3
- package/dist/src/Error.d.ts.map +1 -1
- package/dist/src/Error.js +16 -0
- package/dist/src/Identicon.js +4 -4
- package/dist/src/LockManager.d.ts +74 -0
- package/dist/src/LockManager.d.ts.map +1 -0
- package/dist/src/LockManager.js +103 -0
- package/dist/src/Microtask.d.ts.map +1 -1
- package/dist/src/Microtask.js +90 -26
- package/dist/src/Object.d.ts.map +1 -1
- package/dist/src/RefCount.d.ts.map +1 -1
- package/dist/src/RefCount.js +153 -68
- package/dist/src/Resource.d.ts +6 -6
- package/dist/src/Resource.d.ts.map +1 -1
- package/dist/src/Resource.js +211 -162
- package/dist/src/Schedule.d.ts +5 -5
- package/dist/src/Schedule.d.ts.map +1 -1
- package/dist/src/Schedule.js +53 -44
- package/dist/src/Sqlite.d.ts +2 -0
- package/dist/src/Sqlite.d.ts.map +1 -1
- package/dist/src/Sqlite.js +66 -41
- package/dist/src/Task.d.ts +99 -123
- package/dist/src/Task.d.ts.map +1 -1
- package/dist/src/Task.js +273 -256
- package/dist/src/Test.d.ts +14 -15
- package/dist/src/Test.d.ts.map +1 -1
- package/dist/src/Time.d.ts +5 -0
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +5 -0
- package/dist/src/Type.d.ts +7 -0
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +7 -0
- package/dist/src/Types.d.ts +0 -8
- package/dist/src/Types.d.ts.map +1 -1
- package/dist/src/WebSocket.d.ts.map +1 -1
- package/dist/src/WebSocket.js +7 -6
- package/dist/src/Worker.d.ts +42 -8
- package/dist/src/Worker.d.ts.map +1 -1
- package/dist/src/Worker.js +292 -112
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/local-first/Db.d.ts +5 -4
- package/dist/src/local-first/Db.d.ts.map +1 -1
- package/dist/src/local-first/Db.js +43 -37
- package/dist/src/local-first/Evolu.d.ts +3 -2
- package/dist/src/local-first/Evolu.d.ts.map +1 -1
- package/dist/src/local-first/Evolu.js +90 -80
- package/dist/src/local-first/Owner.d.ts.map +1 -1
- package/dist/src/local-first/Shared.d.ts +65 -54
- package/dist/src/local-first/Shared.d.ts.map +1 -1
- package/dist/src/local-first/Shared.js +390 -376
- package/package.json +1 -1
- package/src/Array.ts +8 -8
- package/src/Assert.ts +11 -6
- package/src/Error.ts +5 -4
- package/src/Identicon.ts +4 -4
- package/src/LockManager.ts +181 -0
- package/src/Microtask.ts +17 -11
- package/src/Object.ts +3 -3
- package/src/RefCount.ts +25 -21
- package/src/Resource.ts +63 -56
- package/src/Schedule.ts +70 -48
- package/src/Set.ts +4 -4
- package/src/Sqlite.ts +43 -31
- package/src/Task.ts +392 -430
- package/src/Test.ts +14 -15
- package/src/Time.ts +7 -0
- package/src/Type.ts +9 -0
- package/src/Types.ts +0 -9
- package/src/WebSocket.ts +7 -6
- package/src/Worker.ts +195 -53
- package/src/index.ts +1 -0
- package/src/local-first/Db.ts +86 -61
- package/src/local-first/Evolu.ts +74 -68
- package/src/local-first/Owner.ts +1 -1
- package/src/local-first/Query.ts +1 -1
- package/src/local-first/Shared.ts +485 -476
package/dist/src/Resource.js
CHANGED
|
@@ -70,18 +70,18 @@ export const createResourceRef = (create) => unabortable(async (run) => {
|
|
|
70
70
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
71
71
|
try {
|
|
72
72
|
const resourceRefRun = run.create();
|
|
73
|
-
const
|
|
74
|
-
|
|
73
|
+
const disposer = __addDisposableResource(env_1, new AsyncDisposableStack(), true);
|
|
74
|
+
disposer.use(resourceRefRun);
|
|
75
75
|
const initial = await resourceRefRun(create);
|
|
76
76
|
if (!initial.ok)
|
|
77
77
|
return initial;
|
|
78
78
|
let current = createOwnedResource(initial.value);
|
|
79
|
-
const mutex =
|
|
80
|
-
|
|
79
|
+
const mutex = disposer.use(createMutex());
|
|
80
|
+
disposer.defer(() => current.stack.disposeAsync());
|
|
81
81
|
// Register as the last so disposal aborts further calls first.
|
|
82
82
|
// Repeated registration is safe because disposal is idempotent.
|
|
83
|
-
|
|
84
|
-
const
|
|
83
|
+
disposer.use(resourceRefRun);
|
|
84
|
+
const disposables = disposer.move();
|
|
85
85
|
return ok({
|
|
86
86
|
get: () => resourceRefRun(mutex.withLock(() => ok(current.resource))),
|
|
87
87
|
set: (create) => unabortable(() => resourceRefRun(mutex.withLock(async (run) => {
|
|
@@ -92,7 +92,7 @@ export const createResourceRef = (create) => unabortable(async (run) => {
|
|
|
92
92
|
current = createOwnedResource(next.value);
|
|
93
93
|
return ok();
|
|
94
94
|
}))),
|
|
95
|
-
[Symbol.asyncDispose]: () =>
|
|
95
|
+
[Symbol.asyncDispose]: () => disposables.disposeAsync(),
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
98
|
catch (e_1) {
|
|
@@ -106,173 +106,222 @@ export const createResourceRef = (create) => unabortable(async (run) => {
|
|
|
106
106
|
}
|
|
107
107
|
});
|
|
108
108
|
/** Creates {@link SharedResource}. */
|
|
109
|
-
export const createSharedResource = (create, { idleDisposeAfter, onDisposed } = {}) => unabortable((run) => {
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
env_2.error = e_2;
|
|
129
|
-
env_2.hasError = true;
|
|
130
|
-
}
|
|
131
|
-
finally {
|
|
132
|
-
const result_2 = __disposeResources(env_2);
|
|
133
|
-
if (result_2)
|
|
134
|
-
await result_2;
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
stack.defer(disposeCurrent);
|
|
138
|
-
// Register as the last so disposal aborts further calls first.
|
|
139
|
-
stack.use(sharedResourceRun);
|
|
140
|
-
const moved = stack.move();
|
|
141
|
-
return ok({
|
|
142
|
-
snapshot: () => ({
|
|
143
|
-
isIdle: refCount.getCount() === 0 && !current && !idleDisposeFiber,
|
|
144
|
-
mutex: mutex.snapshot(),
|
|
145
|
-
}),
|
|
146
|
-
get: () => current?.resource,
|
|
147
|
-
acquire: unabortable(() => sharedResourceRun(mutex.withLock(async (run) => {
|
|
148
|
-
if (idleDisposeFiber) {
|
|
149
|
-
idleDisposeFiber.abort();
|
|
150
|
-
idleDisposeFiber = undefined;
|
|
109
|
+
export const createSharedResource = (create, { idleDisposeAfter, onDisposed } = {}) => unabortable(async (run) => {
|
|
110
|
+
const env_2 = { stack: [], error: void 0, hasError: false };
|
|
111
|
+
try {
|
|
112
|
+
const sharedResourceRun = run.create();
|
|
113
|
+
let current;
|
|
114
|
+
let idleDisposeFiber;
|
|
115
|
+
const disposer = __addDisposableResource(env_2, new AsyncDisposableStack(), true);
|
|
116
|
+
const refCount = disposer.use(createRefCount());
|
|
117
|
+
const mutex = disposer.use(createMutex());
|
|
118
|
+
const disposeCurrent = async () => {
|
|
119
|
+
const env_3 = { stack: [], error: void 0, hasError: false };
|
|
120
|
+
try {
|
|
121
|
+
if (!current)
|
|
122
|
+
return;
|
|
123
|
+
const disposer = __addDisposableResource(env_3, new AsyncDisposableStack(), true);
|
|
124
|
+
if (onDisposed)
|
|
125
|
+
disposer.defer(onDisposed);
|
|
126
|
+
disposer.use(current.stack);
|
|
127
|
+
current = undefined;
|
|
151
128
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
return resource;
|
|
156
|
-
current = createOwnedResource(resource.value);
|
|
129
|
+
catch (e_3) {
|
|
130
|
+
env_3.error = e_3;
|
|
131
|
+
env_3.hasError = true;
|
|
157
132
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (refCount.decrement() > 0)
|
|
163
|
-
return ok();
|
|
164
|
-
if (!idleDisposeAfter) {
|
|
165
|
-
await disposeCurrent();
|
|
166
|
-
return ok();
|
|
133
|
+
finally {
|
|
134
|
+
const result_3 = __disposeResources(env_3);
|
|
135
|
+
if (result_3)
|
|
136
|
+
await result_3;
|
|
167
137
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
138
|
+
};
|
|
139
|
+
disposer.defer(disposeCurrent);
|
|
140
|
+
// Register as the last so disposal aborts further calls first.
|
|
141
|
+
disposer.use(sharedResourceRun);
|
|
142
|
+
const disposables = disposer.move();
|
|
143
|
+
return ok({
|
|
144
|
+
acquire: unabortable(() => sharedResourceRun(mutex.withLock(async (run) => {
|
|
145
|
+
if (idleDisposeFiber) {
|
|
146
|
+
idleDisposeFiber.abort();
|
|
173
147
|
idleDisposeFiber = undefined;
|
|
148
|
+
}
|
|
149
|
+
if (!current) {
|
|
150
|
+
const resource = await run(create);
|
|
151
|
+
if (!resource.ok)
|
|
152
|
+
return resource;
|
|
153
|
+
current = createOwnedResource(resource.value);
|
|
154
|
+
}
|
|
155
|
+
refCount.increment();
|
|
156
|
+
return ok(current.resource);
|
|
157
|
+
}))),
|
|
158
|
+
release: unabortable(() => sharedResourceRun(mutex.withLock(async () => {
|
|
159
|
+
if (refCount.decrement() > 0)
|
|
160
|
+
return ok();
|
|
161
|
+
if (!idleDisposeAfter) {
|
|
174
162
|
await disposeCurrent();
|
|
175
163
|
return ok();
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
164
|
+
}
|
|
165
|
+
idleDisposeFiber = sharedResourceRun(async (run) => {
|
|
166
|
+
const slept = await run(sleep(idleDisposeAfter));
|
|
167
|
+
if (!slept.ok)
|
|
168
|
+
return slept;
|
|
169
|
+
return run(mutex.withLock(async () => {
|
|
170
|
+
idleDisposeFiber = undefined;
|
|
171
|
+
await disposeCurrent();
|
|
172
|
+
return ok();
|
|
173
|
+
}));
|
|
174
|
+
});
|
|
175
|
+
return ok();
|
|
176
|
+
}))),
|
|
177
|
+
getCount: () => sharedResourceRun(mutex.withLock(() => ok(refCount.getCount()))),
|
|
178
|
+
get: () => current?.resource,
|
|
179
|
+
snapshot: () => ({
|
|
180
|
+
isIdle: refCount.getCount() === 0 && !current && !idleDisposeFiber,
|
|
181
|
+
mutex: mutex.snapshot(),
|
|
182
|
+
}),
|
|
183
|
+
[Symbol.asyncDispose]: () => disposables.disposeAsync(),
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
catch (e_2) {
|
|
187
|
+
env_2.error = e_2;
|
|
188
|
+
env_2.hasError = true;
|
|
189
|
+
}
|
|
190
|
+
finally {
|
|
191
|
+
const result_2 = __disposeResources(env_2);
|
|
192
|
+
if (result_2)
|
|
193
|
+
await result_2;
|
|
194
|
+
}
|
|
183
195
|
});
|
|
184
196
|
export function createSharedResourceByKey(create, { idleDisposeAfter, lookup = identity, onDisposed, } = {}) {
|
|
185
|
-
return unabortable((run) => {
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
stack
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
return ok({
|
|
203
|
-
get: (key) => sharedResourcesByKey.get(key)?.get(),
|
|
204
|
-
acquire: (key) => unabortable(() => sharedResourceByKeyRun(mutexByKey.withLock(key, async (run) => {
|
|
205
|
-
let sharedResource = sharedResourcesByKey.get(key);
|
|
206
|
-
if (!sharedResource) {
|
|
207
|
-
const sharedResourceResult = await run(createSharedResource(create(key), {
|
|
208
|
-
idleDisposeAfter,
|
|
209
|
-
onDisposed: () => {
|
|
210
|
-
onDisposed?.(key);
|
|
211
|
-
void sharedResourceByKeyRun(mutexByKey.withLock(key, async () => {
|
|
212
|
-
if (sharedResource &&
|
|
213
|
-
sharedResourcesByKey.get(key) === sharedResource &&
|
|
214
|
-
sharedResource.snapshot().isIdle) {
|
|
215
|
-
sharedResourcesByKey.delete(key);
|
|
216
|
-
await sharedResource[Symbol.asyncDispose]();
|
|
217
|
-
}
|
|
218
|
-
return ok();
|
|
219
|
-
}));
|
|
220
|
-
},
|
|
221
|
-
}));
|
|
222
|
-
assertNotAborted(sharedResourceResult);
|
|
223
|
-
sharedResource = sharedResourceResult.value;
|
|
224
|
-
sharedResourcesByKey.set(key, sharedResource);
|
|
197
|
+
return unabortable(async (run) => {
|
|
198
|
+
const env_4 = { stack: [], error: void 0, hasError: false };
|
|
199
|
+
try {
|
|
200
|
+
const sharedResourceByKeyRun = run.create();
|
|
201
|
+
const sharedResourcesByKey = createLookupMap({
|
|
202
|
+
lookup,
|
|
203
|
+
});
|
|
204
|
+
const disposer = __addDisposableResource(env_4, new AsyncDisposableStack(), true);
|
|
205
|
+
const mutexByKey = disposer.use(createMutexByKey({ lookup }));
|
|
206
|
+
disposer.defer(async () => {
|
|
207
|
+
const env_5 = { stack: [], error: void 0, hasError: false };
|
|
208
|
+
try {
|
|
209
|
+
const disposer = __addDisposableResource(env_5, new AsyncDisposableStack(), true);
|
|
210
|
+
for (const resource of sharedResourcesByKey.values())
|
|
211
|
+
disposer.use(resource);
|
|
212
|
+
await disposer.disposeAsync();
|
|
213
|
+
sharedResourcesByKey.clear();
|
|
225
214
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
const sharedResource = sharedResourcesByKey.get(key);
|
|
230
|
-
assert(sharedResource, "Release must not be called more times than acquire.");
|
|
231
|
-
return sharedResourceByKeyRun(sharedResource.release);
|
|
232
|
-
}))),
|
|
233
|
-
getCount: (key) => () => sharedResourceByKeyRun(mutexByKey.withLock(key, async (run) => {
|
|
234
|
-
const sharedResource = sharedResourcesByKey.get(key);
|
|
235
|
-
if (!sharedResource)
|
|
236
|
-
return ok(zeroNonNegativeInt);
|
|
237
|
-
return run(sharedResource.getCount);
|
|
238
|
-
})),
|
|
239
|
-
snapshot: () => {
|
|
240
|
-
const resourcesByKey = new Map();
|
|
241
|
-
const mutexSnapshotsByKey = new Map();
|
|
242
|
-
for (const [key, sharedResource] of sharedResourcesByKey.entries()) {
|
|
243
|
-
const resource = sharedResource.get();
|
|
244
|
-
if (!resource)
|
|
245
|
-
continue;
|
|
246
|
-
resourcesByKey.set(key, resource);
|
|
247
|
-
mutexSnapshotsByKey.set(key, mutexByKey.snapshot(key));
|
|
215
|
+
catch (e_5) {
|
|
216
|
+
env_5.error = e_5;
|
|
217
|
+
env_5.hasError = true;
|
|
248
218
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
219
|
+
finally {
|
|
220
|
+
const result_5 = __disposeResources(env_5);
|
|
221
|
+
if (result_5)
|
|
222
|
+
await result_5;
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
// Register as the last so disposal aborts further calls first.
|
|
226
|
+
disposer.use(sharedResourceByKeyRun);
|
|
227
|
+
const disposables = disposer.move();
|
|
228
|
+
return ok({
|
|
229
|
+
acquire: (key) => unabortable(() => sharedResourceByKeyRun(mutexByKey.withLock(key, async (run) => {
|
|
230
|
+
let sharedResource = sharedResourcesByKey.get(key);
|
|
231
|
+
if (!sharedResource) {
|
|
232
|
+
const sharedResourceResult = await run(createSharedResource(create(key), {
|
|
233
|
+
idleDisposeAfter,
|
|
234
|
+
onDisposed: () => {
|
|
235
|
+
onDisposed?.(key);
|
|
236
|
+
void sharedResourceByKeyRun(mutexByKey.withLock(key, async () => {
|
|
237
|
+
if (sharedResource &&
|
|
238
|
+
sharedResourcesByKey.get(key) === sharedResource &&
|
|
239
|
+
sharedResource.snapshot().isIdle) {
|
|
240
|
+
sharedResourcesByKey.delete(key);
|
|
241
|
+
await sharedResource[Symbol.asyncDispose]();
|
|
242
|
+
}
|
|
243
|
+
return ok();
|
|
244
|
+
}));
|
|
245
|
+
},
|
|
246
|
+
}));
|
|
247
|
+
assertNotAborted(sharedResourceResult);
|
|
248
|
+
sharedResource = sharedResourceResult.value;
|
|
249
|
+
sharedResourcesByKey.set(key, sharedResource);
|
|
250
|
+
}
|
|
251
|
+
return run(sharedResource.acquire);
|
|
252
|
+
}))),
|
|
253
|
+
release: (key) => unabortable(() => sharedResourceByKeyRun(mutexByKey.withLock(key, async () => {
|
|
254
|
+
const sharedResource = sharedResourcesByKey.get(key);
|
|
255
|
+
assert(sharedResource, "Release must not be called more times than acquire.");
|
|
256
|
+
return sharedResourceByKeyRun(sharedResource.release);
|
|
257
|
+
}))),
|
|
258
|
+
getCount: (key) => () => sharedResourceByKeyRun(mutexByKey.withLock(key, async (run) => {
|
|
259
|
+
const sharedResource = sharedResourcesByKey.get(key);
|
|
260
|
+
if (!sharedResource)
|
|
261
|
+
return ok(zeroNonNegativeInt);
|
|
262
|
+
return run(sharedResource.getCount);
|
|
263
|
+
})),
|
|
264
|
+
get: (key) => sharedResourcesByKey.get(key)?.get(),
|
|
265
|
+
snapshot: () => {
|
|
266
|
+
const resourcesByKey = new Map();
|
|
267
|
+
const mutexSnapshotsByKey = new Map();
|
|
268
|
+
for (const [key, sharedResource] of sharedResourcesByKey.entries()) {
|
|
269
|
+
const resource = sharedResource.get();
|
|
270
|
+
if (!resource)
|
|
271
|
+
continue;
|
|
272
|
+
resourcesByKey.set(key, resource);
|
|
273
|
+
mutexSnapshotsByKey.set(key, mutexByKey.snapshot(key));
|
|
274
|
+
}
|
|
275
|
+
return {
|
|
276
|
+
resourcesByKey,
|
|
277
|
+
mutexByKey: mutexSnapshotsByKey,
|
|
278
|
+
};
|
|
279
|
+
},
|
|
280
|
+
[Symbol.asyncDispose]: () => disposables.disposeAsync(),
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
catch (e_4) {
|
|
284
|
+
env_4.error = e_4;
|
|
285
|
+
env_4.hasError = true;
|
|
286
|
+
}
|
|
287
|
+
finally {
|
|
288
|
+
const result_4 = __disposeResources(env_4);
|
|
289
|
+
if (result_4)
|
|
290
|
+
await result_4;
|
|
291
|
+
}
|
|
256
292
|
});
|
|
257
293
|
}
|
|
258
294
|
export function createSharedResourceByKeyWithClaims(create, { idleDisposeAfter, resourceLookup = identity, claimLookup = identity, onFirstClaimAdded, onLastClaimRemoved, } = {}) {
|
|
259
295
|
return unabortable(async (run) => {
|
|
260
|
-
const
|
|
296
|
+
const env_6 = { stack: [], error: void 0, hasError: false };
|
|
261
297
|
try {
|
|
262
298
|
const sharedResourceClaimsRun = run.create();
|
|
263
|
-
const
|
|
299
|
+
const disposer = __addDisposableResource(env_6, new AsyncDisposableStack(), true);
|
|
264
300
|
const keyByClaim = createRelation({
|
|
265
301
|
lookupA: claimLookup,
|
|
266
302
|
lookupB: resourceLookup,
|
|
267
303
|
});
|
|
268
|
-
const pairRefCountsByClaim =
|
|
269
|
-
|
|
270
|
-
|
|
304
|
+
const pairRefCountsByClaim = disposer.adopt(createLookupMap({ lookup: claimLookup }), (pairRefCountsByClaim) => {
|
|
305
|
+
const env_7 = { stack: [], error: void 0, hasError: false };
|
|
306
|
+
try {
|
|
307
|
+
const disposer = __addDisposableResource(env_7, new DisposableStack(), false);
|
|
308
|
+
disposer.defer(() => {
|
|
309
|
+
pairRefCountsByClaim.clear();
|
|
310
|
+
});
|
|
311
|
+
for (const pairRefCountByKey of pairRefCountsByClaim.values()) {
|
|
312
|
+
disposer.use(pairRefCountByKey);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
catch (e_7) {
|
|
316
|
+
env_7.error = e_7;
|
|
317
|
+
env_7.hasError = true;
|
|
318
|
+
}
|
|
319
|
+
finally {
|
|
320
|
+
__disposeResources(env_7);
|
|
271
321
|
}
|
|
272
|
-
pairRefCountsByClaim.clear();
|
|
273
322
|
});
|
|
274
|
-
const mutexByKey =
|
|
275
|
-
|
|
323
|
+
const mutexByKey = disposer.use(createMutexByKey({ lookup: resourceLookup }));
|
|
324
|
+
disposer.defer(() => {
|
|
276
325
|
keyByClaim.clear();
|
|
277
326
|
});
|
|
278
327
|
const sharedResourcesByKeyResult = await sharedResourceClaimsRun(createSharedResourceByKey(create, {
|
|
@@ -280,9 +329,9 @@ export function createSharedResourceByKeyWithClaims(create, { idleDisposeAfter,
|
|
|
280
329
|
lookup: resourceLookup,
|
|
281
330
|
}));
|
|
282
331
|
assertNotAborted(sharedResourcesByKeyResult);
|
|
283
|
-
const sharedResourcesByKey =
|
|
332
|
+
const sharedResourcesByKey = disposer.use(sharedResourcesByKeyResult.value);
|
|
284
333
|
// Register as the last so disposal aborts further calls first.
|
|
285
|
-
|
|
334
|
+
disposer.use(sharedResourceClaimsRun);
|
|
286
335
|
/** Asserts that one call does not contain the same logical key twice. */
|
|
287
336
|
const assertNoDuplicateResourceKeys = (resourceKeys) => {
|
|
288
337
|
assert(createLookupSet({
|
|
@@ -290,7 +339,7 @@ export function createSharedResourceByKeyWithClaims(create, { idleDisposeAfter,
|
|
|
290
339
|
values: resourceKeys,
|
|
291
340
|
}).size === resourceKeys.length, "resourceKeys must not contain lookup duplicates.");
|
|
292
341
|
};
|
|
293
|
-
const
|
|
342
|
+
const disposables = disposer.move();
|
|
294
343
|
return ok({
|
|
295
344
|
addClaim: (claim, resourceKeys) => unabortable(() => sharedResourceClaimsRun(async (run) => {
|
|
296
345
|
assertNoDuplicateResourceKeys(resourceKeys);
|
|
@@ -365,17 +414,17 @@ export function createSharedResourceByKeyWithClaims(create, { idleDisposeAfter,
|
|
|
365
414
|
}
|
|
366
415
|
return resources;
|
|
367
416
|
},
|
|
368
|
-
[Symbol.asyncDispose]: () =>
|
|
417
|
+
[Symbol.asyncDispose]: () => disposables.disposeAsync(),
|
|
369
418
|
});
|
|
370
419
|
}
|
|
371
|
-
catch (
|
|
372
|
-
|
|
373
|
-
|
|
420
|
+
catch (e_6) {
|
|
421
|
+
env_6.error = e_6;
|
|
422
|
+
env_6.hasError = true;
|
|
374
423
|
}
|
|
375
424
|
finally {
|
|
376
|
-
const
|
|
377
|
-
if (
|
|
378
|
-
await
|
|
425
|
+
const result_6 = __disposeResources(env_6);
|
|
426
|
+
if (result_6)
|
|
427
|
+
await result_6;
|
|
379
428
|
}
|
|
380
429
|
});
|
|
381
430
|
}
|
package/dist/src/Schedule.d.ts
CHANGED
|
@@ -677,15 +677,15 @@ export declare function passthrough<Output, Input>(schedule: Schedule<Output, In
|
|
|
677
677
|
* // Outputs: 100, 300, 700, 1500, ... (cumulative)
|
|
678
678
|
*
|
|
679
679
|
* // Collect all outputs
|
|
680
|
-
* const collected = foldSchedule
|
|
681
|
-
*
|
|
682
|
-
* delay,
|
|
683
|
-
*
|
|
680
|
+
* const collected = foldSchedule<ReadonlyArray<Millis>, Millis>(
|
|
681
|
+
* [],
|
|
682
|
+
* (acc, delay) => [...acc, delay],
|
|
683
|
+
* )(take(3)(spaced("1s")));
|
|
684
684
|
* // Outputs: [1000], [1000, 1000], [1000, 1000, 1000]
|
|
685
685
|
*
|
|
686
686
|
* // Count attempts with custom output
|
|
687
687
|
* const counted = foldSchedule(
|
|
688
|
-
* { attempts: 0, lastDelay:
|
|
688
|
+
* { attempts: 0, lastDelay: minMillis },
|
|
689
689
|
* (acc, delay: Millis) => ({
|
|
690
690
|
* attempts: acc.attempts + 1,
|
|
691
691
|
* lastDelay: delay,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schedule.d.ts","sourceRoot":"","sources":["../../src/Schedule.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"Schedule.d.ts","sourceRoot":"","sources":["../../src/Schedule.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,a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