| 627 | } |
| 628 | |
| 629 | export class CancellationTokenSource { |
| 630 | private _token: CancellationToken | undefined; |
| 631 | private _emitter: EventEmitter<any> | undefined; |
| 632 | private _isCancelled = false; |
| 633 | |
| 634 | get token(): CancellationToken { |
| 635 | if (!this._token) { |
| 636 | this._emitter = new EventEmitter<any>(); |
| 637 | this._token = { |
| 638 | isCancellationRequested: this._isCancelled, |
| 639 | onCancellationRequested: this._emitter.event, |
| 640 | }; |
| 641 | } |
| 642 | return this._token; |
| 643 | } |
| 644 | |
| 645 | cancel(): void { |
| 646 | if (!this._isCancelled) { |
| 647 | this._isCancelled = true; |
| 648 | if (this._emitter) { |
| 649 | this._emitter.fire(undefined); |
| 650 | } |
| 651 | // Update token state |
| 652 | if (this._token) { |
| 653 | (this._token as any).isCancellationRequested = true; |
| 654 | } |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | dispose(): void { |
| 659 | if (this._emitter) { |
| 660 | this._emitter.dispose(); |
| 661 | this._emitter = undefined; |
| 662 | } |
| 663 | this._token = undefined; |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | // ===== Progress ===== |
| 668 |
nothing calls this directly
no outgoing calls
no test coverage detected