@trpc/server 11.0.0-rc.645 → 11.0.0-rc.657
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/adapters/aws-lambda/index.js +1 -1
- package/dist/adapters/aws-lambda/index.mjs +1 -1
- package/dist/adapters/express.js +1 -1
- package/dist/adapters/express.mjs +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.js +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.mjs +1 -1
- package/dist/adapters/next-app-dir/nextAppDirCaller.js +1 -1
- package/dist/adapters/next-app-dir/nextAppDirCaller.mjs +1 -1
- package/dist/adapters/next-app-dir/notFound.js +1 -1
- package/dist/adapters/next-app-dir/notFound.mjs +1 -1
- package/dist/adapters/next-app-dir/redirect.js +15 -3
- package/dist/adapters/next-app-dir/redirect.mjs +14 -2
- package/dist/adapters/next.js +1 -1
- package/dist/adapters/next.mjs +1 -1
- package/dist/adapters/node-http/incomingMessageToRequest.js +1 -1
- package/dist/adapters/node-http/incomingMessageToRequest.mjs +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +1 -1
- package/dist/adapters/node-http/writeResponse.js +1 -1
- package/dist/adapters/node-http/writeResponse.mjs +1 -1
- package/dist/adapters/standalone.js +1 -1
- package/dist/adapters/standalone.mjs +1 -1
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/adapters/ws.js +144 -65
- package/dist/adapters/ws.mjs +144 -65
- package/dist/bundle-analysis.json +190 -183
- package/dist/http.js +1 -1
- package/dist/http.mjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/node_modules/.pnpm/@rollup_plugin-typescript@12.1.1_rollup@4.27.4_tslib@2.8.1_typescript@5.7.2/node_modules/tslib/tslib.es6.js +73 -0
- package/dist/rpc.js +1 -1
- package/dist/rpc.mjs +1 -1
- package/dist/shared.js +1 -1
- package/dist/shared.mjs +1 -1
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts +1 -1
- package/dist/unstable-core-do-not-import/error/TRPCError.js +14 -2
- package/dist/unstable-core-do-not-import/error/TRPCError.mjs +13 -1
- package/dist/unstable-core-do-not-import/http/resolveResponse.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/resolveResponse.js +3 -9
- package/dist/unstable-core-do-not-import/http/resolveResponse.mjs +3 -9
- package/dist/unstable-core-do-not-import/middleware.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/jsonl.d.ts +8 -34
- package/dist/unstable-core-do-not-import/stream/jsonl.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/jsonl.js +338 -209
- package/dist/unstable-core-do-not-import/stream/jsonl.mjs +337 -208
- package/dist/unstable-core-do-not-import/stream/sse.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/sse.js +143 -74
- package/dist/unstable-core-do-not-import/stream/sse.mjs +144 -75
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.d.ts +1 -0
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.js +103 -10
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.mjs +104 -12
- package/dist/unstable-core-do-not-import/stream/utils/disposable.d.ts +17 -0
- package/dist/unstable-core-do-not-import/stream/utils/disposable.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/utils/disposable.js +44 -0
- package/dist/unstable-core-do-not-import/stream/utils/disposable.mjs +41 -0
- package/dist/unstable-core-do-not-import/stream/utils/timerResource.d.ts +1 -2
- package/dist/unstable-core-do-not-import/stream/utils/timerResource.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/utils/timerResource.js +8 -10
- package/dist/unstable-core-do-not-import/stream/utils/timerResource.mjs +8 -10
- package/dist/unstable-core-do-not-import/stream/utils/withPing.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/utils/withPing.js +113 -24
- package/dist/unstable-core-do-not-import/stream/utils/withPing.mjs +114 -25
- package/dist/unstable-core-do-not-import/transformer.d.ts +1 -1
- package/dist/unstable-core-do-not-import.d.ts +1 -0
- package/dist/unstable-core-do-not-import.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import.js +3 -0
- package/dist/unstable-core-do-not-import.mjs +1 -0
- package/dist/vendor/unpromise/unpromise.js +17 -6
- package/dist/vendor/unpromise/unpromise.mjs +13 -2
- package/package.json +3 -4
- package/src/adapters/ws.ts +7 -8
- package/src/unstable-core-do-not-import/http/resolveResponse.ts +3 -9
- package/src/unstable-core-do-not-import/stream/jsonl.ts +128 -153
- package/src/unstable-core-do-not-import/stream/sse.ts +64 -79
- package/src/unstable-core-do-not-import/stream/utils/asyncIterable.ts +50 -48
- package/src/unstable-core-do-not-import/stream/utils/disposable.ts +52 -0
- package/src/unstable-core-do-not-import/stream/utils/timerResource.ts +17 -15
- package/src/unstable-core-do-not-import/stream/utils/withPing.ts +18 -19
- package/src/unstable-core-do-not-import.ts +1 -0
- package/dist/node_modules/.pnpm/@swc_helpers@0.5.13/node_modules/@swc/helpers/esm/_define_property.js +0 -11
- package/dist/node_modules/.pnpm/@swc_helpers@0.5.13/node_modules/@swc/helpers/esm/_define_property.mjs +0 -9
|
@@ -2,12 +2,17 @@ import { Unpromise } from '../../vendor/unpromise';
|
|
|
2
2
|
import { getTRPCErrorFromUnknown } from '../error/TRPCError';
|
|
3
3
|
import { isAbortError } from '../http/isAbortError';
|
|
4
4
|
import type { MaybePromise } from '../types';
|
|
5
|
-
import { identity } from '../utils';
|
|
5
|
+
import { identity, run } from '../utils';
|
|
6
6
|
import type { EventSourceLike } from './sse.types';
|
|
7
7
|
import type { inferTrackedOutput } from './tracked';
|
|
8
8
|
import { isTrackedEnvelope } from './tracked';
|
|
9
9
|
import { takeWithGrace, withMaxDuration } from './utils/asyncIterable';
|
|
10
|
+
import { makeAsyncResource } from './utils/disposable';
|
|
10
11
|
import { readableStreamFrom } from './utils/readableStreamFrom';
|
|
12
|
+
import {
|
|
13
|
+
disposablePromiseTimerResult,
|
|
14
|
+
timerResource,
|
|
15
|
+
} from './utils/timerResource';
|
|
11
16
|
import { PING_SYM, withPing } from './utils/withPing';
|
|
12
17
|
|
|
13
18
|
type Serialize = (value: any) => any;
|
|
@@ -260,21 +265,10 @@ async function withTimeout<T>(opts: {
|
|
|
260
265
|
timeoutMs: number;
|
|
261
266
|
onTimeout: () => Promise<NoInfer<T>>;
|
|
262
267
|
}): Promise<T> {
|
|
263
|
-
|
|
268
|
+
using timeoutPromise = timerResource(opts.timeoutMs);
|
|
269
|
+
const res = await Unpromise.race([opts.promise, timeoutPromise.start()]);
|
|
264
270
|
|
|
265
|
-
|
|
266
|
-
timeoutId = setTimeout(() => {
|
|
267
|
-
resolve(null);
|
|
268
|
-
}, opts.timeoutMs);
|
|
269
|
-
});
|
|
270
|
-
let res;
|
|
271
|
-
try {
|
|
272
|
-
res = await Unpromise.race([opts.promise, timeoutPromise]);
|
|
273
|
-
} finally {
|
|
274
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
275
|
-
clearTimeout(timeoutId!);
|
|
276
|
-
}
|
|
277
|
-
if (res === null) {
|
|
271
|
+
if (res === disposablePromiseTimerResult) {
|
|
278
272
|
return await opts.onTimeout();
|
|
279
273
|
}
|
|
280
274
|
return res;
|
|
@@ -381,76 +375,67 @@ export function sseStreamConsumer<TConfig extends ConsumerConfig>(
|
|
|
381
375
|
},
|
|
382
376
|
});
|
|
383
377
|
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
|
|
378
|
+
const getStreamResource = () => {
|
|
379
|
+
let stream = createStream();
|
|
380
|
+
let reader = stream.getReader();
|
|
381
|
+
|
|
382
|
+
async function dispose() {
|
|
383
|
+
await reader.cancel();
|
|
384
|
+
_es = null;
|
|
385
|
+
}
|
|
387
386
|
|
|
388
|
-
return
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
387
|
+
return makeAsyncResource(
|
|
388
|
+
{
|
|
389
|
+
read() {
|
|
390
|
+
return reader.read();
|
|
391
|
+
},
|
|
392
|
+
async recreate() {
|
|
393
|
+
await dispose();
|
|
394
|
+
|
|
395
|
+
stream = createStream();
|
|
396
|
+
reader = stream.getReader();
|
|
397
|
+
},
|
|
393
398
|
},
|
|
394
|
-
|
|
399
|
+
dispose,
|
|
400
|
+
);
|
|
395
401
|
};
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
eventSource: _es,
|
|
415
|
-
},
|
|
416
|
-
done: false,
|
|
417
|
-
};
|
|
418
|
-
// Close and release old reader
|
|
419
|
-
await stream.cancel();
|
|
420
|
-
|
|
421
|
-
// Create new reader
|
|
422
|
-
stream = getNewStreamAndReader();
|
|
423
|
-
|
|
424
|
-
return res;
|
|
402
|
+
|
|
403
|
+
return run(async function* () {
|
|
404
|
+
await using stream = getStreamResource();
|
|
405
|
+
|
|
406
|
+
while (true) {
|
|
407
|
+
let promise = stream.read();
|
|
408
|
+
|
|
409
|
+
const timeoutMs = clientOptions.reconnectAfterInactivityMs;
|
|
410
|
+
if (timeoutMs) {
|
|
411
|
+
promise = withTimeout({
|
|
412
|
+
promise,
|
|
413
|
+
timeoutMs,
|
|
414
|
+
onTimeout: async () => {
|
|
415
|
+
const res: Awaited<typeof promise> = {
|
|
416
|
+
value: {
|
|
417
|
+
type: 'timeout',
|
|
418
|
+
ms: timeoutMs,
|
|
419
|
+
eventSource: _es,
|
|
425
420
|
},
|
|
426
|
-
|
|
427
|
-
|
|
421
|
+
done: false,
|
|
422
|
+
};
|
|
423
|
+
// Close and release old reader
|
|
424
|
+
await stream.recreate();
|
|
428
425
|
|
|
429
|
-
|
|
426
|
+
return res;
|
|
427
|
+
},
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
430
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
value: result.value,
|
|
440
|
-
done: false,
|
|
441
|
-
};
|
|
442
|
-
},
|
|
443
|
-
async return() {
|
|
444
|
-
await stream.cancel();
|
|
445
|
-
return {
|
|
446
|
-
value: undefined,
|
|
447
|
-
done: true,
|
|
448
|
-
};
|
|
449
|
-
},
|
|
450
|
-
};
|
|
451
|
-
return iterator;
|
|
452
|
-
},
|
|
453
|
-
};
|
|
431
|
+
const result = await promise;
|
|
432
|
+
|
|
433
|
+
if (result.done) {
|
|
434
|
+
return result.value;
|
|
435
|
+
}
|
|
436
|
+
yield result.value;
|
|
437
|
+
}
|
|
438
|
+
});
|
|
454
439
|
}
|
|
455
440
|
|
|
456
441
|
export const sseHeaders = {
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { Unpromise } from '../../../vendor/unpromise';
|
|
2
|
+
import { makeAsyncResource } from './disposable';
|
|
2
3
|
import { disposablePromiseTimerResult, timerResource } from './timerResource';
|
|
3
4
|
|
|
5
|
+
export function iteratorResource<TYield, TReturn, TNext>(
|
|
6
|
+
iterable: AsyncIterable<TYield, TReturn, TNext>,
|
|
7
|
+
): AsyncIterator<TYield, TReturn, TNext> & AsyncDisposable {
|
|
8
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
9
|
+
|
|
10
|
+
return makeAsyncResource(iterator, async () => {
|
|
11
|
+
await iterator.return?.();
|
|
12
|
+
});
|
|
13
|
+
}
|
|
4
14
|
/**
|
|
5
15
|
* Derives a new {@link AsyncGenerator} based on {@link iterable}, that automatically stops after the specified duration.
|
|
6
16
|
*/
|
|
@@ -8,34 +18,29 @@ export async function* withMaxDuration<T>(
|
|
|
8
18
|
iterable: AsyncIterable<T>,
|
|
9
19
|
opts: { maxDurationMs: number },
|
|
10
20
|
): AsyncGenerator<T> {
|
|
11
|
-
|
|
21
|
+
await using iterator = iteratorResource(iterable);
|
|
22
|
+
|
|
23
|
+
using timer = timerResource(opts.maxDurationMs);
|
|
12
24
|
|
|
13
|
-
const
|
|
14
|
-
try {
|
|
15
|
-
const timerPromise = timer.start();
|
|
25
|
+
const timerPromise = timer.start();
|
|
16
26
|
|
|
17
|
-
|
|
18
|
-
|
|
27
|
+
// declaration outside the loop for garbage collection reasons
|
|
28
|
+
let result: null | IteratorResult<T> | typeof disposablePromiseTimerResult;
|
|
19
29
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
30
|
+
while (true) {
|
|
31
|
+
result = await Unpromise.race([iterator.next(), timerPromise]);
|
|
32
|
+
if (result === disposablePromiseTimerResult) {
|
|
33
|
+
// cancelled due to timeout
|
|
24
34
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
yield result.value;
|
|
32
|
-
// free up reference for garbage collection
|
|
33
|
-
result = null;
|
|
35
|
+
const res = await iterator.return?.();
|
|
36
|
+
return res?.value;
|
|
37
|
+
}
|
|
38
|
+
if (result.done) {
|
|
39
|
+
return result;
|
|
34
40
|
}
|
|
35
|
-
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
timer[Symbol.dispose]();
|
|
41
|
+
yield result.value;
|
|
42
|
+
// free up reference for garbage collection
|
|
43
|
+
result = null;
|
|
39
44
|
}
|
|
40
45
|
}
|
|
41
46
|
|
|
@@ -51,37 +56,34 @@ export async function* takeWithGrace<T>(
|
|
|
51
56
|
gracePeriodMs: number;
|
|
52
57
|
},
|
|
53
58
|
): AsyncGenerator<T> {
|
|
54
|
-
|
|
59
|
+
await using iterator = iteratorResource(iterable);
|
|
55
60
|
|
|
56
61
|
// declaration outside the loop for garbage collection reasons
|
|
57
62
|
let result: null | IteratorResult<T> | typeof disposablePromiseTimerResult;
|
|
58
63
|
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
let count = opts.count;
|
|
64
|
+
using timer = timerResource(opts.gracePeriodMs);
|
|
62
65
|
|
|
63
|
-
|
|
64
|
-
// never resolves
|
|
65
|
-
});
|
|
66
|
+
let count = opts.count;
|
|
66
67
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
68
|
+
let timerPromise = new Promise<typeof disposablePromiseTimerResult>(() => {
|
|
69
|
+
// never resolves
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
while (true) {
|
|
73
|
+
result = await Unpromise.race([iterator.next(), timerPromise]);
|
|
74
|
+
if (result === disposablePromiseTimerResult) {
|
|
75
|
+
// cancelled
|
|
76
|
+
const res = await iterator.return?.();
|
|
77
|
+
return res?.value;
|
|
78
|
+
}
|
|
79
|
+
if (result.done) {
|
|
80
|
+
return result.value;
|
|
81
|
+
}
|
|
82
|
+
yield result.value;
|
|
83
|
+
if (--count === 0) {
|
|
84
|
+
timerPromise = timer.start();
|
|
83
85
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
// free up reference for garbage collection
|
|
87
|
+
result = null;
|
|
86
88
|
}
|
|
87
89
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// @ts-expect-error - polyfilling symbol
|
|
2
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
3
|
+
Symbol.dispose ??= Symbol();
|
|
4
|
+
|
|
5
|
+
// @ts-expect-error - polyfilling symbol
|
|
6
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
7
|
+
Symbol.asyncDispose ??= Symbol();
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Takes a value and a dispose function and returns a new object that implements the Disposable interface.
|
|
11
|
+
* The returned object is the original value augmented with a Symbol.dispose method.
|
|
12
|
+
* @param thing The value to make disposable
|
|
13
|
+
* @param dispose Function to call when disposing the resource
|
|
14
|
+
* @returns The original value with Symbol.dispose method added
|
|
15
|
+
*/
|
|
16
|
+
export function makeResource<T>(thing: T, dispose: () => void): T & Disposable {
|
|
17
|
+
const it = thing as T & Disposable;
|
|
18
|
+
|
|
19
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
20
|
+
if (it[Symbol.dispose]) {
|
|
21
|
+
throw new Error('Symbol.dispose already exists');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
25
|
+
it[Symbol.dispose] = dispose;
|
|
26
|
+
|
|
27
|
+
return it;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Takes a value and an async dispose function and returns a new object that implements the AsyncDisposable interface.
|
|
32
|
+
* The returned object is the original value augmented with a Symbol.asyncDispose method.
|
|
33
|
+
* @param thing The value to make async disposable
|
|
34
|
+
* @param dispose Async function to call when disposing the resource
|
|
35
|
+
* @returns The original value with Symbol.asyncDispose method added
|
|
36
|
+
*/
|
|
37
|
+
export function makeAsyncResource<T>(
|
|
38
|
+
thing: T,
|
|
39
|
+
dispose: () => Promise<void>,
|
|
40
|
+
): T & AsyncDisposable {
|
|
41
|
+
const it = thing as T & AsyncDisposable;
|
|
42
|
+
|
|
43
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
44
|
+
if (it[Symbol.asyncDispose]) {
|
|
45
|
+
throw new Error('Symbol.asyncDispose already exists');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
49
|
+
it[Symbol.asyncDispose] = dispose;
|
|
50
|
+
|
|
51
|
+
return it;
|
|
52
|
+
}
|
|
@@ -1,27 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
Symbol.dispose ??= Symbol();
|
|
1
|
+
import { makeResource } from './disposable';
|
|
3
2
|
|
|
4
3
|
export const disposablePromiseTimerResult = Symbol();
|
|
4
|
+
|
|
5
5
|
export function timerResource(ms: number) {
|
|
6
6
|
let timer: ReturnType<typeof setTimeout> | null = null;
|
|
7
7
|
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
return makeResource(
|
|
9
|
+
{
|
|
10
|
+
start() {
|
|
11
|
+
if (timer) {
|
|
12
|
+
throw new Error('Timer already started');
|
|
13
|
+
}
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
const promise = new Promise<typeof disposablePromiseTimerResult>(
|
|
16
|
+
(resolve) => {
|
|
17
|
+
timer = setTimeout(() => resolve(disposablePromiseTimerResult), ms);
|
|
18
|
+
},
|
|
19
|
+
);
|
|
20
|
+
return promise;
|
|
21
|
+
},
|
|
20
22
|
},
|
|
21
|
-
|
|
23
|
+
() => {
|
|
22
24
|
if (timer) {
|
|
23
25
|
clearTimeout(timer);
|
|
24
26
|
}
|
|
25
27
|
},
|
|
26
|
-
|
|
28
|
+
);
|
|
27
29
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Unpromise } from '../../../vendor/unpromise';
|
|
2
|
+
import { iteratorResource } from './asyncIterable';
|
|
2
3
|
import { disposablePromiseTimerResult, timerResource } from './timerResource';
|
|
3
4
|
|
|
4
5
|
export const PING_SYM = Symbol('ping');
|
|
@@ -11,7 +12,8 @@ export async function* withPing<TValue>(
|
|
|
11
12
|
iterable: AsyncIterable<TValue>,
|
|
12
13
|
pingIntervalMs: number,
|
|
13
14
|
): AsyncGenerator<TValue | typeof PING_SYM> {
|
|
14
|
-
|
|
15
|
+
await using iterator = iteratorResource(iterable);
|
|
16
|
+
|
|
15
17
|
// declaration outside the loop for garbage collection reasons
|
|
16
18
|
let result:
|
|
17
19
|
| null
|
|
@@ -19,30 +21,27 @@ export async function* withPing<TValue>(
|
|
|
19
21
|
| typeof disposablePromiseTimerResult;
|
|
20
22
|
|
|
21
23
|
let nextPromise = iterator.next();
|
|
24
|
+
|
|
22
25
|
while (true) {
|
|
23
|
-
|
|
26
|
+
using pingPromise = timerResource(pingIntervalMs);
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
result = await Unpromise.race([nextPromise, pingPromise.start()]);
|
|
28
|
+
result = await Unpromise.race([nextPromise, pingPromise.start()]);
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
if (result === disposablePromiseTimerResult) {
|
|
31
|
+
// cancelled
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
yield PING_SYM;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
34
36
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
if (result.done) {
|
|
38
|
+
return result.value;
|
|
39
|
+
}
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
nextPromise = iterator.next();
|
|
42
|
+
yield result.value;
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
} finally {
|
|
45
|
-
pingPromise[Symbol.dispose]();
|
|
46
|
-
}
|
|
44
|
+
// free up reference for garbage collection
|
|
45
|
+
result = null;
|
|
47
46
|
}
|
|
48
47
|
}
|
|
@@ -36,6 +36,7 @@ export * from './unstable-core-do-not-import/stream/sse.types';
|
|
|
36
36
|
export * from './unstable-core-do-not-import/stream/sse';
|
|
37
37
|
export * from './unstable-core-do-not-import/stream/tracked';
|
|
38
38
|
export * from './unstable-core-do-not-import/stream/utils/createDeferred';
|
|
39
|
+
export * from './unstable-core-do-not-import/stream/utils/disposable';
|
|
39
40
|
export * from './unstable-core-do-not-import/transformer';
|
|
40
41
|
export * from './unstable-core-do-not-import/types';
|
|
41
42
|
export * from './unstable-core-do-not-import/utils';
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function _define_property(obj, key, value) {
|
|
4
|
-
if (key in obj) {
|
|
5
|
-
Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });
|
|
6
|
-
} else obj[key] = value;
|
|
7
|
-
|
|
8
|
-
return obj;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
exports._ = _define_property;
|