1453
1454
public get(token: CancellationToken): Promise<T> {
1455
>
// If a previous in-flight computation had all of its callers cancel, the pool's
promptsServiceImpl.ts
1456
>
// token will have fired and the computation may have rejected/aborted. A new
1457
>
// caller arriving in that window must not inherit that cancellation, so start
1458
>
// fresh.
1459
>
if (this.cachedPool?.token.isCancellationRequested) {
1460
this.cachedPromise = undefined;
1461
this.cachedPool = undefined;
1462
}
1464
>
if (this.cachedPromise === undefined) {
1465
>
// Aggregate callers' tokens so the shared computation is cancelled
1466
>
// only after every live caller has cancelled. A single caller's
1467
>
// cancellation no longer aborts the work for the others.
1468
>
pool = new CancellationTokenPool();
1469
>
const promise = this.computeFn(pool.token).catch(err => {
1470
if (this.cachedPromise === promise) {
1471
this.cachedPromise = undefined;
1472
}
1473
throw err;
1475
>
// The pool is only meaningful while the computation is in flight.
1476
>
promise.finally(() => {
1477
>
if (this.cachedPool === pool) {
1478
>
this.cachedPool = undefined;
1479
>
}
1480
>
pool!.dispose();
1481
>
});
1482
>
this.cachedPromise = promise;
1483
>
this.cachedPool = pool;
1484
>
}
1485
>
pool?.add(token);
1486
>
return raceCancellationError(this.cachedPromise, token);
1487
>
}
1488
1489
public refresh(): void {