src/vs/platform/terminal/common/requestStore.ts

73 LOC · 71 covered · 2 uncovered · 8 ranges · 5 concepts · 4 introducers · 3 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the filesrc/vs/platform/log/common/log.ts · 926 LOCcommon/log.tssrc/vs/platform/log/common/logService.ts · 57 LOCcommon/logService.tsptyHostService.ts ×54 · 735 introduced LOCptyHostService.ts ×54requestStore.ts ×2 · 8 introduced LOCrequestStore.ts ×2requestStore.ts ×1 · 2 introduced LOCrequestStore.ts ×1logService.ts ×10 · 63 introduced LOClogService.ts ×10requestStore.ts ×4 · 52 introduced LOCrequestStore.ts ×4requestStore.test|title=RequestStore should reject the promise when the request times out|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/terminal/test/common/requestStore.test|title=RequestStore should reject the promise when the request times out|occurrence=1requestStore.test|title=…requestStore.test|title=RequestStore should resolve requests|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/terminal/test/common/requestStore.test|title=RequestStore should resolve requests|occurrence=1requestStore.test|title=…ptyHostService.test|title=PtyHostService restartPtyHost disposes listeners registered during pty host startup|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/terminal/test/node/ptyHostService.test|title=PtyHostService restartPtyHost disposes listeners registered during pty host startup|occurrence=1ptyHostService.test|titl…Focused file · src/vs/platform/terminal/common/requestStore.ts · 73 LOCcommon/requestStore.ts

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- requestStore.ts ×4
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { timeout } from '../../../base/common/async.js';
7 > import { CancellationTokenSource } from '../../../base/common/cancellation.js';
8 > import { Emitter } from '../../../base/common/event.js';
9 > import { Disposable, dispose, IDisposable, toDisposable } from '../../../base/common/lifecycle.js';
10 > import { ILogService } from '../../log/common/log.js';
11 >
12 > /**
13 > * A helper class to track requests that have replies. Using this it's easy to implement an event
14 > * that accepts a reply.
15 > */
16 > export class RequestStore<T, RequestArgs> extends Disposable {
17 > private _lastRequestId = 0;
18 > private readonly _timeout: number;
19 > private _pendingRequests: Map<number, (resolved: T) => void> = new Map();
20 > private _pendingRequestDisposables: Map<number, IDisposable[]> = new Map();
21 >
22 > private readonly _onCreateRequest = this._register(new Emitter<RequestArgs & { requestId: number }>());
23 > readonly onCreateRequest = this._onCreateRequest.event;
24 >
25 > /**
26 > * @param timeout How long in ms to allow requests to go unanswered for, undefined will use the
27 > * default (15 seconds).
28 > */
29 > constructor(
30 > timeout: number | undefined,
31 > @ILogService private readonly _logService: ILogService
32 > ) {
33 > super();
34 > this._timeout = timeout === undefined ? 15000 : timeout;
35 > this._register(toDisposable(() => {
36 > for (const d of this._pendingRequestDisposables.values()) {
37 > dispose(d); requestStore.ts ×1
38 > }
40 > }
41 >
42 > /**
43 > * Creates a request.
44 > * @param args The arguments to pass to the onCreateRequest event.
45 > */
46 > createRequest(args: RequestArgs): Promise<T> {
47 > return new Promise<T>((resolve, reject) => { logService.ts ×10
48 > const requestId = ++this._lastRequestId;
49 > this._pendingRequests.set(requestId, resolve);
50 > this._onCreateRequest.fire({ requestId, ...args });
51 > const tokenSource = new CancellationTokenSource();
52 > timeout(this._timeout, tokenSource.token).then(() => reject(`Request ${requestId} timed out (${this._timeout}ms)`));
53 > this._pendingRequestDisposables.set(requestId, [toDisposable(() => tokenSource.cancel())]);
54 > });
55 > }
57 > /**
58 > * Accept a reply to a request.
59 > * @param requestId The request ID originating from the onCreateRequest event.
60 > * @param data The reply data.
61 > */
62 > acceptReply(requestId: number, data: T) {
63 > const resolveRequest = this._pendingRequests.get(requestId); requestStore.ts ×2
64 > if (resolveRequest) {
65 > this._pendingRequests.delete(requestId);
66 > dispose(this._pendingRequestDisposables.get(requestId) || []);
67 > this._pendingRequestDisposables.delete(requestId);
68 > resolveRequest(data);
69 > } else {
70 this._logService.warn(`RequestStore#acceptReply was called without receiving a matching request ${requestId}`);
71 }