| 81 | } |
| 82 | |
| 83 | export class CancellationTokenSource { |
| 84 | |
| 85 | private _token: CancellationToken; |
| 86 | |
| 87 | get token(): CancellationToken { |
| 88 | if (!this._token) { |
| 89 | // be lazy and create the token only when |
| 90 | // actually needed |
| 91 | this._token = new MutableToken(); |
| 92 | } |
| 93 | return this._token; |
| 94 | } |
| 95 | |
| 96 | cancel(): void { |
| 97 | if (!this._token) { |
| 98 | // save an object by returning the default |
| 99 | // cancelled token when cancellation happens |
| 100 | // before someone asks for the token |
| 101 | this._token = CancellationToken.Cancelled; |
| 102 | } else { |
| 103 | (<MutableToken>this._token).cancel(); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | dispose(): void { |
| 108 | this.cancel(); |
| 109 | } |
| 110 | } |
nothing calls this directly
no outgoing calls
no test coverage detected