import { CancellationToken } from 'vscode' ; import { IActionContext , UserCancelledError } from 'vscode-azureextensionui' ; import { CancellationTokenSource } from 'vscode-jsonrpc' ; export class Cancellation { public static cantCancel : Cancellation = new Cancellation ( new CancellationTokenSource ( ) . token ) ; public constructor ( public token , public actionContext ? ) { this . throwIfCancelled ( ) ; } public throwIfCancelled ( ) { throwOnCancel ( this . token , this . actionContext ) ; } } export function throwOnCancel ( token , actionContext ? ) { if ( token . isCancellationRequested ) { if ( actionContext ) { actionContext . telemetry . properties . cancelStep = 'vscode' ; } throw new UserCancelledError ( ) ; } }