// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for details. import { OutputChannelLogger } from "./log/OutputChannelLogger"; export abstract class AbstractDeviceTracker { protected logger: OutputChannelLogger; protected isStop: boolean; constructor() { this.logger = OutputChannelLogger.getMainChannel(); this.isStop = false; } public abstract start(): Promise; public abstract stop(): void; protected async queryDevicesLoop(): Promise { try { await this.queryDevices(); if (!this.isStop) { // It's important to schedule the next check AFTER the current one has completed // to avoid simultaneous queries which can cause multiple user input prompts. setTimeout(() => this.queryDevicesLoop(), 3000); } } catch (err) { this.logger.error((err as Error).toString()); } } protected abstract queryDevices(): Promise; }