當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript CancellationTokenSource.dispose方法代碼示例

本文整理匯總了TypeScript中vscode.CancellationTokenSource.dispose方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript CancellationTokenSource.dispose方法的具體用法?TypeScript CancellationTokenSource.dispose怎麽用?TypeScript CancellationTokenSource.dispose使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在vscode.CancellationTokenSource的用法示例。


在下文中一共展示了CancellationTokenSource.dispose方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: test

	test('#7013 - input without options', function () {
		const source = new CancellationTokenSource();
		let p = window.showInputBox(undefined, source.token);
		assert.ok(typeof p === 'object');
		source.dispose();
	});
開發者ID:sandy081,項目名稱:vscode,代碼行數:6,代碼來源:window.test.ts

示例2: show

    async show(
        placeHolder: string,
        options: ReferencesQuickPickOptions = {}
    ): Promise<ReferencesQuickPickItem | CommandQuickPickItem | undefined> {
        const cancellation = new CancellationTokenSource();

        let scope;
        if (options.goBack) {
            scope = await Container.keyboard.beginScope({ left: options.goBack });
        }

        let autoPick;
        try {
            let items = this.getItems(options, cancellation.token);
            if (options.autoPick) {
                items = items.then(itms => {
                    if (itms.length <= 1) {
                        autoPick = itms[0];
                        cancellation.cancel();
                    }
                    return itms;
                });
            }

            let pick;
            if (options.allowEnteringRefs) {
                placeHolder += `${GlyphChars.Space.repeat(3)}(select or enter a reference)`;

                const quickpick = window.createQuickPick<ReferencesQuickPickItem | CommandQuickPickItem>();
                quickpick.busy = true;
                quickpick.enabled = false;
                quickpick.placeholder = placeHolder;
                quickpick.ignoreFocusOut = getQuickPickIgnoreFocusOut();
                quickpick.show();

                quickpick.items = await items;
                quickpick.busy = false;
                quickpick.enabled = true;

                pick = await new Promise<ReferencesQuickPickItem | CommandQuickPickItem | undefined>(resolve => {
                    cancellation.token.onCancellationRequested(() => quickpick.hide());

                    quickpick.onDidHide(() => resolve(undefined));
                    quickpick.onDidAccept(async () => {
                        if (quickpick.selectedItems.length === 0) {
                            quickpick.busy = true;
                            quickpick.enabled = false;

                            const ref = quickpick.value;
                            if (
                                this.repoPath === undefined ||
                                (await Container.git.validateReference(this.repoPath, ref))
                            ) {
                                resolve(new RefQuickPickItem(ref));
                            }
                            else {
                                quickpick.title = 'You must enter a valid reference';
                                quickpick.busy = false;
                                quickpick.enabled = true;
                                return;
                            }
                        }
                        else {
                            resolve(quickpick.selectedItems[0]);
                        }

                        quickpick.hide();
                    });
                });

                quickpick.dispose();
            }
            else {
                pick = await window.showQuickPick(
                    items,
                    {
                        placeHolder: placeHolder,
                        ignoreFocusOut: getQuickPickIgnoreFocusOut()
                    },
                    cancellation.token
                );
            }

            if (pick === undefined && autoPick !== undefined) {
                pick = autoPick;
            }

            if (pick === undefined) {
                cancellation.cancel();
            }

            return pick;
        }
        finally {
            if (scope !== undefined) {
                await scope.dispose();
            }

            cancellation.dispose();
        }
//.........這裏部分代碼省略.........
開發者ID:chrisleaman,項目名稱:vscode-gitlens,代碼行數:101,代碼來源:referencesQuickPick.ts


注:本文中的vscode.CancellationTokenSource.dispose方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。