UNPKG

3.67 kBJavaScriptView Raw
1"use strict";
2/********************************************************************************
3* Copyright (c) 2021 STMicroelectronics and others.
4*
5* This program and the accompanying materials are made available under the
6* terms of the Eclipse Public License 2.0 which is available at
7* http://www.eclipse.org/legal/epl-2.0.
8*
9* This Source Code may also be made available under the following Secondary
10* Licenses when the conditions for such availability set forth in the Eclipse
11* Public License v. 2.0 are satisfied: GNU General Public License, version 2
12* with the GNU Classpath Exception which is available at
13* https://www.gnu.org/software/classpath/license.html.
14*
15* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16*******************************************************************************/
17var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21 return c > 3 && r && Object.defineProperty(target, key, r), r;
22};
23var __metadata = (this && this.__metadata) || function (k, v) {
24 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25};
26Object.defineProperty(exports, "__esModule", { value: true });
27exports.NullBackendStopwatch = exports.DefaultBackendStopwatch = exports.BackendStopwatchOptions = exports.stopwatchPath = exports.BackendStopwatch = void 0;
28/* eslint-disable @typescript-eslint/no-explicit-any */
29const inversify_1 = require("inversify");
30const stopwatch_1 = require("./stopwatch");
31exports.BackendStopwatch = Symbol('BackendStopwatch');
32/** API path of the stopwatch service that exposes the back-end stopwatch to clients. */
33exports.stopwatchPath = '/services/stopwatch';
34exports.BackendStopwatchOptions = Symbol('BackendStopwatchOptions');
35/**
36 * Default implementation of the (remote) back-end stopwatch service.
37 */
38let DefaultBackendStopwatch = class DefaultBackendStopwatch {
39 constructor() {
40 this.measurements = new Map();
41 this.idSequence = 0;
42 }
43 start(name, options) {
44 const result = ++this.idSequence;
45 this.measurements.set(result, this.stopwatch.start(name, options));
46 return result;
47 }
48 stop(measurementToken, message, messageArgs) {
49 const measurement = this.measurements.get(measurementToken);
50 if (measurement) {
51 this.measurements.delete(measurementToken);
52 measurement.log(message, ...messageArgs);
53 }
54 }
55};
56__decorate([
57 (0, inversify_1.inject)(stopwatch_1.Stopwatch),
58 __metadata("design:type", stopwatch_1.Stopwatch)
59], DefaultBackendStopwatch.prototype, "stopwatch", void 0);
60DefaultBackendStopwatch = __decorate([
61 (0, inversify_1.injectable)()
62], DefaultBackendStopwatch);
63exports.DefaultBackendStopwatch = DefaultBackendStopwatch;
64/**
65 * No-op implementation of the (remote) back-end stopwatch service.
66 */
67let NullBackendStopwatch = class NullBackendStopwatch {
68 start() {
69 return Promise.resolve(0);
70 }
71 stop() {
72 return Promise.resolve();
73 }
74};
75NullBackendStopwatch = __decorate([
76 (0, inversify_1.injectable)()
77], NullBackendStopwatch);
78exports.NullBackendStopwatch = NullBackendStopwatch;
79//# sourceMappingURL=measurement-protocol.js.map
\No newline at end of file