@gmitch215/folio 1.0.1 → 1.2.0

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.
Files changed (130) hide show
  1. package/README.md +98 -460
  2. package/dist/boot.d.ts +1 -0
  3. package/dist/boot.js +1 -0
  4. package/dist/browser/index.d.ts +73 -0
  5. package/dist/browser/index.js +277 -0
  6. package/dist/browser.d.ts +1 -68
  7. package/dist/browser.js +1 -274
  8. package/dist/continuation.d.ts +1 -0
  9. package/dist/continuation.js +1 -0
  10. package/dist/{compiler.d.ts → execution/compiler.d.ts} +1 -1
  11. package/dist/{compiler.js → execution/compiler.js} +5 -12
  12. package/dist/{coordinator.d.ts → execution/coordinator.d.ts} +1 -1
  13. package/dist/{coordinator.js → execution/coordinator.js} +55 -8
  14. package/dist/{extract.d.ts → execution/extract.d.ts} +22 -13
  15. package/dist/{extract.js → execution/extract.js} +137 -10
  16. package/dist/execution/fold.d.ts +44 -0
  17. package/dist/execution/fold.js +105 -0
  18. package/dist/{guards.d.ts → execution/guards.d.ts} +2 -1
  19. package/dist/execution/runs.d.ts +44 -0
  20. package/dist/execution/runs.js +182 -0
  21. package/dist/{transaction.d.ts → execution/transaction.d.ts} +10 -0
  22. package/dist/execution/types.d.ts +221 -0
  23. package/dist/folds/affine-state.d.ts +142 -0
  24. package/dist/folds/affine-state.js +737 -0
  25. package/dist/folds/affine.d.ts +148 -0
  26. package/dist/folds/affine.js +562 -0
  27. package/dist/folds/boundaries.d.ts +48 -0
  28. package/dist/folds/boundaries.js +119 -0
  29. package/dist/folds/certified.d.ts +55 -0
  30. package/dist/folds/certified.js +178 -0
  31. package/dist/folds/certify.d.ts +87 -0
  32. package/dist/folds/certify.js +2611 -0
  33. package/dist/footprints/memo.d.ts +74 -0
  34. package/dist/footprints/memo.js +256 -0
  35. package/dist/footprints/ranges.d.ts +78 -0
  36. package/dist/footprints/ranges.js +263 -0
  37. package/dist/footprints/read-scan.d.ts +18 -0
  38. package/dist/footprints/read-scan.js +94 -0
  39. package/dist/footprints/read-windows.d.ts +77 -0
  40. package/dist/footprints/read-windows.js +245 -0
  41. package/dist/index.d.ts +16 -4
  42. package/dist/index.js +14 -2
  43. package/dist/iteration/admission.d.ts +149 -0
  44. package/dist/iteration/admission.js +201 -0
  45. package/dist/iteration/index.d.ts +239 -0
  46. package/dist/iteration/index.js +1210 -0
  47. package/dist/iteration/inline.d.ts +182 -0
  48. package/dist/{inline.js → iteration/inline.js} +277 -21
  49. package/dist/{iteration-owner.d.ts → iteration/owner.d.ts} +16 -3
  50. package/dist/{iteration-owner.js → iteration/owner.js} +6 -5
  51. package/dist/iteration/worker.js +216 -0
  52. package/dist/{managed.d.ts → managed/index.d.ts} +75 -3
  53. package/dist/managed/index.js +817 -0
  54. package/dist/managed/outbox.d.ts +128 -0
  55. package/dist/managed/outbox.js +156 -0
  56. package/dist/managed/pool.d.ts +221 -0
  57. package/dist/managed/pool.js +310 -0
  58. package/dist/managed/tasks.d.ts +154 -0
  59. package/dist/managed/tasks.js +183 -0
  60. package/dist/{bake.d.ts → memory/bake.d.ts} +12 -6
  61. package/dist/{bake.js → memory/bake.js} +9 -7
  62. package/dist/memory/continuation.d.ts +141 -0
  63. package/dist/memory/continuation.js +495 -0
  64. package/dist/memory/elastic-peer.d.ts +20 -0
  65. package/dist/memory/elastic-peer.js +39 -0
  66. package/dist/memory/elastic-sql.d.ts +11 -0
  67. package/dist/memory/elastic-sql.js +35 -0
  68. package/dist/memory/elastic.d.ts +130 -0
  69. package/dist/memory/elastic.js +475 -0
  70. package/dist/memory/growth-governor.d.ts +16 -0
  71. package/dist/memory/growth-governor.js +42 -0
  72. package/dist/memory/imports.d.ts +10 -0
  73. package/dist/memory/imports.js +89 -0
  74. package/dist/{iteration-layout.d.ts → memory/iteration-layout.d.ts} +61 -1
  75. package/dist/{iteration-layout.js → memory/iteration-layout.js} +54 -3
  76. package/dist/memory/lease.d.ts +45 -0
  77. package/dist/memory/lease.js +274 -0
  78. package/dist/{pages.d.ts → memory/pages.d.ts} +3 -3
  79. package/dist/memory.d.ts +5 -10
  80. package/dist/memory.js +5 -89
  81. package/dist/{context.d.ts → node/context.d.ts} +17 -3
  82. package/dist/{context.js → node/context.js} +60 -14
  83. package/dist/{host.d.ts → node/host.d.ts} +1 -1
  84. package/dist/{host.js → node/host.js} +2 -2
  85. package/dist/{node.d.ts → node/index.d.ts} +46 -49
  86. package/dist/{node.js → node/index.js} +101 -26
  87. package/dist/{tasks.d.ts → node/tasks.d.ts} +16 -17
  88. package/dist/{tasks.js → node/tasks.js} +12 -11
  89. package/dist/node/worker.d.ts +1 -0
  90. package/dist/{worker.js → node/worker.js} +2 -2
  91. package/dist/ownership/index.d.ts +161 -0
  92. package/dist/ownership/index.js +6565 -0
  93. package/dist/ownership/redirect.d.ts +30 -0
  94. package/dist/ownership/redirect.js +179 -0
  95. package/dist/ownership/slices.d.ts +44 -0
  96. package/dist/ownership/slices.js +72 -0
  97. package/dist/{frames.d.ts → remote/frames.d.ts} +6 -2
  98. package/dist/remote/frames.js +306 -0
  99. package/dist/{remote.d.ts → remote/index.d.ts} +7 -2
  100. package/dist/{remote.js → remote/index.js} +7 -2
  101. package/dist/routing/index.d.ts +203 -0
  102. package/dist/routing/index.js +671 -0
  103. package/dist/routing/worker.d.ts +1 -0
  104. package/dist/routing/worker.js +4 -0
  105. package/dist/slices/index.d.ts +126 -0
  106. package/dist/slices/index.js +441 -0
  107. package/dist/slices/worker.d.ts +1 -0
  108. package/dist/slices/worker.js +38 -0
  109. package/dist/workers.d.ts +5 -0
  110. package/dist/workers.js +5 -0
  111. package/package.json +32 -46
  112. package/dist/frames.js +0 -159
  113. package/dist/inline.d.ts +0 -68
  114. package/dist/iteration-admission.d.ts +0 -76
  115. package/dist/iteration-admission.js +0 -72
  116. package/dist/iteration-worker.js +0 -150
  117. package/dist/iteration.d.ts +0 -163
  118. package/dist/iteration.js +0 -435
  119. package/dist/managed.js +0 -421
  120. /package/dist/{browser-worker.d.ts → browser/worker.d.ts} +0 -0
  121. /package/dist/{browser-worker.js → browser/worker.js} +0 -0
  122. /package/dist/{guards.js → execution/guards.js} +0 -0
  123. /package/dist/{import-order.d.ts → execution/import-order.d.ts} +0 -0
  124. /package/dist/{import-order.js → execution/import-order.js} +0 -0
  125. /package/dist/{transaction.js → execution/transaction.js} +0 -0
  126. /package/dist/{iteration-worker.d.ts → execution/types.js} +0 -0
  127. /package/dist/{worker.d.ts → iteration/worker.d.ts} +0 -0
  128. /package/dist/{pages.js → memory/pages.js} +0 -0
  129. /package/dist/{values.d.ts → remote/values.d.ts} +0 -0
  130. /package/dist/{values.js → remote/values.js} +0 -0
package/dist/managed.js DELETED
@@ -1,421 +0,0 @@
1
- import { Coordinator } from "./coordinator.js";
2
- import { decodeFrame, decodeResults, encodeFrame, encodeResults, encodeSnapshot, restoreSnapshot, snapshotLength, validateIdentity } from "./frames.js";
3
- import { SpeculationLimit, transaction } from "./transaction.js";
4
- // workers rpc rejects serialized arguments over 32 MiB; the margin covers the other arguments and serializer tags
5
- const rpcFrameLimit = 32 * 1048576 - 4096;
6
- function integer(value, minimum, maximum, label) {
7
- if (!Number.isSafeInteger(value) || value < minimum || value > maximum)
8
- throw new RangeError(`invalid ${label}`);
9
- return value;
10
- }
11
- /**
12
- * The lane runtime: runs tracked regions from a binary frame against a private copy of the
13
- * frozen snapshot and returns byte read and write sets. Holds no state between frames.
14
- */
15
- export class FolioLane {
16
- #module;
17
- #initial;
18
- #maximum;
19
- #maximumFrameBytes;
20
- #maximumMemoryBytes;
21
- #memory;
22
- #instance;
23
- #active;
24
- constructor(module, options) {
25
- this.#module = module;
26
- this.#initial = integer(options.initial, 0, 65536, 'initial memory');
27
- this.#maximum = integer(options.maximum, this.#initial, 65536, 'maximum memory');
28
- this.#maximumMemoryBytes = options.maximumMemoryBytes ?? 32 * 1048576;
29
- this.#maximumFrameBytes = options.maximumFrameBytes ?? this.#maximumMemoryBytes + 1048576;
30
- integer(this.#maximumMemoryBytes, 65536, 0x100000000, 'lane memory limit');
31
- integer(this.#maximumFrameBytes, 65536, 0x100100000, 'lane frame limit');
32
- }
33
- /** Validates the frame, runs its calls in order and returns the encoded results. */
34
- execute(frame) {
35
- const { header, payload } = decodeFrame(frame, this.#maximumFrameBytes);
36
- validateIdentity(header);
37
- integer(header.fuel, 1, 1000000000, 'fuel');
38
- integer(header.maxBytes, 8, 1048576, 'tracking budget');
39
- if (!Array.isArray(header.calls) || !header.calls.length || header.calls.length > 16)
40
- throw new RangeError('invalid lane call count');
41
- for (const call of header.calls) {
42
- if (typeof call?.export !== 'string' ||
43
- !Array.isArray(call.args) ||
44
- call.args.length > 256 ||
45
- call.args.some((value) => typeof value !== 'number' && typeof value !== 'bigint'))
46
- throw new TypeError('invalid lane call');
47
- }
48
- const memoryBytes = snapshotLength(header.snapshot, payload);
49
- const pages = memoryBytes / 65536;
50
- if (!Number.isInteger(pages) ||
51
- pages < this.#initial ||
52
- pages > this.#maximum ||
53
- memoryBytes > this.#maximumMemoryBytes)
54
- throw new RangeError('invalid lane snapshot');
55
- if (!this.#memory || !this.#instance || this.#memory.buffer.byteLength !== memoryBytes) {
56
- const binding = WebAssembly.Module.imports(this.#module).filter((item) => item.kind === 'memory');
57
- if (binding.length !== 1)
58
- throw new TypeError('one lane memory required');
59
- this.#memory = new WebAssembly.Memory({
60
- initial: pages,
61
- maximum: this.#maximum,
62
- shared: true
63
- });
64
- this.#instance = new WebAssembly.Instance(this.#module, {
65
- [binding[0].module]: { [binding[0].name]: this.#memory },
66
- folio: {
67
- load: (...args) => this.#active.load(...args),
68
- store: (...args) => this.#active.store(...args),
69
- load64: (...args) => this.#active.load64(...args),
70
- store64: (...args) => this.#active.store64(...args),
71
- copy: (...args) => this.#active.copy(...args),
72
- fill: (...args) => this.#active.fill(...args),
73
- exhausted: () => {
74
- throw new SpeculationLimit('speculative instruction budget');
75
- }
76
- }
77
- });
78
- }
79
- restoreSnapshot(new Uint8Array(this.#memory.buffer), payload, header.snapshot);
80
- let remaining = header.maxBytes;
81
- const results = [];
82
- for (const call of header.calls) {
83
- if (remaining <= 0) {
84
- results.push({ reads: [], writes: [], exhausted: true });
85
- continue;
86
- }
87
- this.#active = transaction(this.#memory, remaining);
88
- let error, value;
89
- try {
90
- this.#instance.exports.__folio_set_fuel(header.fuel);
91
- const entry = this.#instance.exports[call.export];
92
- if (typeof entry !== 'function')
93
- throw new TypeError('unknown lane export');
94
- value = entry(...call.args);
95
- }
96
- catch (caught) {
97
- error = caught;
98
- }
99
- if (error instanceof RangeError) {
100
- results.push({ reads: [], writes: [], exhausted: true });
101
- continue;
102
- }
103
- const result = this.#active.result(value, error);
104
- remaining -= result.reads.length + result.writes.length;
105
- results.push(result);
106
- }
107
- this.#active = undefined;
108
- return encodeResults(header, results, this.#maximumFrameBytes);
109
- }
110
- /** Drops the instance and its memory; a later frame builds them again. */
111
- close() {
112
- this.#active = this.#instance = this.#memory = undefined;
113
- }
114
- }
115
- /**
116
- * The owner side of the managed backend. The original Wasm stack keeps control flow and host
117
- * effects, and JSPI joins regions that lanes execute over copied snapshots.
118
- */
119
- export class ManagedFolio {
120
- /** The original native exports. */
121
- exports;
122
- /** Optimization refusals and fallbacks seen so far. */
123
- diagnostics = [];
124
- #artifact;
125
- #lanes;
126
- #instance;
127
- #serial = new WebAssembly.Global({ value: 'i32', mutable: true }, 1);
128
- #pendingGlobal = new WebAssembly.Global({ value: 'i32', mutable: true }, 0);
129
- #controlled = new Map();
130
- #promising = new Map();
131
- #maximumSnapshotBytes;
132
- #maximumFrameBytes;
133
- #fuel;
134
- #maxBytes;
135
- #snapshotEncoding;
136
- #session = crypto.randomUUID();
137
- #memory;
138
- #scheduler;
139
- #epoch = 0;
140
- #sequence = 0;
141
- #busy = false;
142
- #closed = false;
143
- #pending;
144
- #closing;
145
- constructor(artifact, options) {
146
- this.#artifact = artifact;
147
- this.#snapshotEncoding = options.snapshotEncoding ?? 'dense';
148
- if (!['auto', 'dense'].includes(this.#snapshotEncoding))
149
- throw new TypeError('invalid snapshot encoding');
150
- this.#lanes = options.lanes;
151
- integer(this.#lanes.length, 1, 64, 'lane count');
152
- this.#maximumSnapshotBytes = integer(options.maximumSnapshotBytes ?? 31 * 1048576, 65536, 0x100000000, 'snapshot limit');
153
- this.#maximumFrameBytes = integer(options.maximumFrameBytes ??
154
- Math.min(this.#maximumSnapshotBytes + 1048576, rpcFrameLimit), 65536, 0x100100000, 'frame limit');
155
- this.#fuel = integer(options.fuel ?? 100000000, 1, 1000000000, 'fuel');
156
- this.#maxBytes = integer(options.maxTransactionBytes ?? 262144, 8, 1048576, 'tracking budget');
157
- const runtime = WebAssembly;
158
- const control = artifact.control;
159
- let module = artifact.original, enabled = false;
160
- if (control &&
161
- artifact.coordinator &&
162
- runtime.Suspending &&
163
- runtime.promising &&
164
- this.#lanes.length > 1) {
165
- const original = WebAssembly.Module.imports(artifact.original);
166
- const retained = WebAssembly.Module.imports(artifact.coordinator).filter((item) => item.module !== control.namespace);
167
- if (JSON.stringify(original) === JSON.stringify(retained)) {
168
- module = artifact.coordinator;
169
- enabled = true;
170
- }
171
- else
172
- this.diagnostics.push('rewritten import sequence differs; using native execution');
173
- }
174
- else
175
- this.diagnostics.push('no active coordinator; using native execution');
176
- const supplied = options.imports ?? Object.create(null);
177
- const memories = WebAssembly.Module.imports(artifact.original).filter((item) => item.kind === 'memory');
178
- if (memories.length > 1 && options.memory)
179
- throw new TypeError('bind multiple memories by name in imports');
180
- const automatic = new Map();
181
- const imports = new Proxy(Object.create(null), {
182
- get: (_, namespace) => {
183
- if (enabled && namespace === control.namespace) {
184
- const bindings = {
185
- [control.serialGlobal]: this.#serial,
186
- [control.pendingGlobal]: this.#pendingGlobal,
187
- barrier: new runtime.Suspending(() => this.#scheduler?.flush()),
188
- poll: new runtime.Suspending(() => this.#scheduler?.poll())
189
- };
190
- for (const region of control.regions)
191
- bindings[region.importName] = new runtime.Suspending((...args) => {
192
- if (this.#scheduler && this.#serial.value === 0)
193
- return this.#scheduler.enqueue({
194
- export: region.exportName,
195
- args
196
- });
197
- this.#instance.exports[region.exportName](...args);
198
- });
199
- return bindings;
200
- }
201
- const bound = Reflect.get(supplied, namespace, supplied);
202
- if (!memories.some((item) => item.module === namespace))
203
- return bound;
204
- if (bound !== undefined &&
205
- (bound === null || !['object', 'function'].includes(typeof bound)))
206
- return bound;
207
- return new Proxy(Object.create(null), {
208
- get: (_, name) => {
209
- if (!memories.some((item) => item.module === namespace && item.name === name))
210
- return bound === undefined
211
- ? undefined
212
- : Reflect.get(bound, name, bound);
213
- let memory = (memories.length === 1 ? options.memory : undefined) ??
214
- (bound === undefined ? undefined : Reflect.get(bound, name, bound));
215
- if (memory === undefined) {
216
- const key = JSON.stringify([namespace, name]);
217
- memory = automatic.get(key);
218
- if (!memory) {
219
- const limits = artifact.memories?.find((item) => item.module === namespace && item.name === name);
220
- if (!limits || limits.memory64)
221
- throw new TypeError(`provide imported memory ${namespace}.${name}`);
222
- memory = new WebAssembly.Memory({
223
- initial: limits.initial,
224
- ...(limits.maximum === undefined
225
- ? {}
226
- : { maximum: limits.maximum }),
227
- shared: limits.shared
228
- });
229
- automatic.set(key, memory);
230
- }
231
- }
232
- if (memories.length === 1)
233
- this.#memory = memory;
234
- return memory;
235
- }
236
- });
237
- }
238
- });
239
- this.#instance = new WebAssembly.Instance(module, imports);
240
- this.exports = Object.create(null);
241
- for (const item of WebAssembly.Module.exports(artifact.original))
242
- Object.defineProperty(this.exports, item.name, {
243
- value: this.#instance.exports[item.name],
244
- enumerable: true
245
- });
246
- Object.freeze(this.exports);
247
- if (enabled) {
248
- this.#memory = this.#instance.exports[control.memoryExport];
249
- for (const name of control.entries)
250
- this.#controlled.set(name, runtime.promising(this.#instance.exports[name]));
251
- }
252
- else if (!this.#memory) {
253
- const own = Object.values(this.exports).filter((item) => item instanceof WebAssembly.Memory);
254
- if (own.length === 1)
255
- this.#memory = own[0];
256
- }
257
- for (const name of options.promising ?? []) {
258
- if (!runtime.promising || typeof this.exports[name] !== 'function')
259
- throw new TypeError('invalid promising export');
260
- this.#promising.set(name, runtime.promising(this.exports[name]));
261
- }
262
- }
263
- /** The canonical memory, which must fit the owner runtime. Throws when there is no unique one. */
264
- get memory() {
265
- if (!this.#memory)
266
- throw new TypeError('no unique accessible memory');
267
- return this.#memory;
268
- }
269
- /** Runs one entry; regions go to lanes and results commit in order. One run at a time. */
270
- run(name, args = [], options = {}) {
271
- if (this.#closed)
272
- return Promise.reject(new Error('folio is closed'));
273
- if (this.#busy)
274
- return Promise.reject(new Error('memory already has an active run'));
275
- const entry = this.exports[name];
276
- if (typeof entry !== 'function')
277
- return Promise.reject(new TypeError('unknown function export'));
278
- const width = Math.min(this.#lanes.length, integer(options.maximumWorkers ?? this.#lanes.length, 1, 64, 'maximumWorkers'));
279
- this.#busy = true;
280
- let resolve, reject;
281
- const pending = new Promise((success, failure) => {
282
- resolve = success;
283
- reject = failure;
284
- });
285
- this.#pending = pending;
286
- void pending
287
- .finally(() => {
288
- this.#busy = false;
289
- this.#pending = undefined;
290
- })
291
- .catch(() => { });
292
- void this.#execute(name, entry, args, width, options.parallel === 'off').then(resolve, reject);
293
- return pending;
294
- }
295
- async #execute(name, entry, args, width, serial) {
296
- const bytes = { sent: 0, received: 0 };
297
- let snapshotBytes = 0;
298
- let transportFallbacks = 0;
299
- const finish = (report) => ({
300
- ...report,
301
- backend: 'managed-coherent',
302
- memoryMode: 'copied',
303
- transportBytes: bytes,
304
- transportFallbacks
305
- });
306
- const controlled = this.#controlled.get(name);
307
- if (serial ||
308
- !controlled ||
309
- width < 2 ||
310
- args.some((value) => typeof value !== 'number' && typeof value !== 'bigint')) {
311
- const value = this.#promising.has(name)
312
- ? await this.#promising.get(name)(...args)
313
- : entry(...args);
314
- return finish({
315
- values: [value],
316
- workers: 0,
317
- regions: 1,
318
- replayed: 0,
319
- fallbacks: 0,
320
- mode: 'serial'
321
- });
322
- }
323
- const epoch = ++this.#epoch;
324
- let snapshotGeneration = -1, snapshot;
325
- const scheduler = new Coordinator({
326
- memory: this.memory,
327
- workerMemory: this.memory,
328
- width,
329
- profile: false,
330
- pending: this.#pendingGlobal,
331
- native: (call) => {
332
- const previous = this.#serial.value;
333
- this.#serial.value = 1;
334
- try {
335
- this.#instance.exports[call.export](...call.args);
336
- }
337
- finally {
338
- this.#serial.value = previous;
339
- }
340
- },
341
- dispatch: async (lane, calls, generation) => {
342
- try {
343
- if (this.memory.buffer.byteLength > this.#maximumSnapshotBytes)
344
- throw new RangeError(`snapshot of ${this.memory.buffer.byteLength} bytes exceeds the limit of ${this.#maximumSnapshotBytes} bytes`);
345
- const identity = { session: this.#session, epoch, sequence: ++this.#sequence };
346
- if (snapshotGeneration !== generation) {
347
- const memory = new Uint8Array(this.memory.buffer);
348
- snapshot =
349
- this.#snapshotEncoding === 'dense'
350
- ? { payload: memory }
351
- : encodeSnapshot(memory);
352
- snapshotGeneration = generation;
353
- }
354
- const frame = encodeFrame({
355
- ...identity,
356
- calls,
357
- fuel: this.#fuel,
358
- maxBytes: this.#maxBytes,
359
- ...(snapshot.snapshot ? { snapshot: snapshot.snapshot } : {})
360
- }, snapshot.payload, this.#maximumFrameBytes);
361
- snapshotBytes += this.memory.buffer.byteLength;
362
- bytes.sent += frame.length;
363
- const response = await this.#lanes[lane].execute(frame);
364
- bytes.received += response.length;
365
- return decodeResults(response, identity, {
366
- maximumFrameBytes: this.#maximumFrameBytes,
367
- memoryBytes: this.memory.buffer.byteLength,
368
- maxBytes: this.#maxBytes,
369
- calls: calls.length
370
- });
371
- }
372
- catch (error) {
373
- transportFallbacks++;
374
- this.diagnostics.push(`lane unavailable; native fallback: ${error instanceof Error ? error.message : String(error)}`);
375
- return calls.map(() => ({ reads: [], writes: [], exhausted: true }));
376
- }
377
- }
378
- });
379
- this.#scheduler = scheduler;
380
- this.#serial.value = 0;
381
- try {
382
- let value, failure, failed = false;
383
- try {
384
- value = await controlled(...args);
385
- }
386
- catch (error) {
387
- failed = true;
388
- failure = error;
389
- }
390
- await scheduler.flush();
391
- if (failed)
392
- throw failure;
393
- scheduler.report.values = [value];
394
- scheduler.report.snapshotBytes = snapshotBytes;
395
- return finish(scheduler.report);
396
- }
397
- finally {
398
- this.#serial.value = 1;
399
- this.#pendingGlobal.value = 0;
400
- this.#scheduler = undefined;
401
- }
402
- }
403
- /** Waits for the active run, then closes every lane. A failed disposer does not skip the rest. */
404
- close() {
405
- if (this.#closing)
406
- return this.#closing;
407
- this.#closed = true;
408
- this.#closing = (async () => {
409
- await this.#pending?.catch(() => { });
410
- const outcomes = await Promise.allSettled(this.#lanes.map(async (lane) => lane.close?.()));
411
- const failed = outcomes.find((result) => result.status === 'rejected');
412
- if (failed?.status === 'rejected')
413
- throw failed.reason;
414
- })();
415
- return this.#closing;
416
- }
417
- /** `await using` support; equivalent to `close()`. */
418
- [Symbol.asyncDispose]() {
419
- return this.close();
420
- }
421
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes