microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
src/extension/abstractDeviceTracker.ts
33lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for details. |
| 3 | |
| 4 | import { OutputChannelLogger } from "./log/OutputChannelLogger"; |
| 5 | |
| 6 | export abstract class AbstractDeviceTracker { |
| 7 | protected logger: OutputChannelLogger; |
| 8 | protected isStop: boolean; |
| 9 | |
| 10 | constructor() { |
| 11 | this.logger = OutputChannelLogger.getMainChannel(); |
| 12 | this.isStop = false; |
| 13 | } |
| 14 | |
| 15 | public abstract start(): Promise<void>; |
| 16 | |
| 17 | public abstract stop(): void; |
| 18 | |
| 19 | protected async queryDevicesLoop(): Promise<void> { |
| 20 | try { |
| 21 | await this.queryDevices(); |
| 22 | if (!this.isStop) { |
| 23 | // It's important to schedule the next check AFTER the current one has completed |
| 24 | // to avoid simultaneous queries which can cause multiple user input prompts. |
| 25 | setTimeout(() => this.queryDevicesLoop(), 3000); |
| 26 | } |
| 27 | } catch (err) { |
| 28 | this.logger.error(err.toString()); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | protected abstract queryDevices(): Promise<void>; |
| 33 | } |
| 34 | |