| 2672 | } |
| 2673 | |
| 2674 | public stop(): Thenable<void> { |
| 2675 | this._initializeResult = undefined; |
| 2676 | if (!this._connectionPromise) { |
| 2677 | this.state = ClientState.Stopped; |
| 2678 | return Promise.resolve(); |
| 2679 | } |
| 2680 | if (this.state === ClientState.Stopping && this._onStop) { |
| 2681 | return this._onStop; |
| 2682 | } |
| 2683 | this.state = ClientState.Stopping; |
| 2684 | this.cleanUp(); |
| 2685 | // unkook listeners |
| 2686 | return this._onStop = this.resolveConnection().then(connection => { |
| 2687 | return connection.shutdown().then(() => { |
| 2688 | connection.exit(); |
| 2689 | connection.dispose(); |
| 2690 | this.state = ClientState.Stopped; |
| 2691 | this._onStop = undefined; |
| 2692 | this._connectionPromise = undefined; |
| 2693 | this._resolvedConnection = undefined; |
| 2694 | }); |
| 2695 | }); |
| 2696 | } |
| 2697 | |
| 2698 | private cleanUp(restart: boolean = false): void { |
| 2699 | if (this._listeners) { |