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


TypeScript vscode.CancellationTokenSource類代碼示例

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


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

示例1: test

	test('showQuickPick, canceled by another picker', function () {

		const result = window.showQuickPick(['eins', 'zwei', 'drei'], { ignoreFocusOut: true }).then(result => {
			assert.equal(result, undefined);
		});

		const source = new CancellationTokenSource();
		source.cancel();
		window.showQuickPick(['eins', 'zwei', 'drei'], undefined, source.token);

		return result;
	});
開發者ID:aminroosta,項目名稱:vscode,代碼行數:12,代碼來源:window.test.ts

示例2: test

	test('showQuickPick, native promise - #11754', async function () {

		const data = new Promise<string[]>(resolve => {
			resolve(['a', 'b', 'c']);
		});

		const source = new CancellationTokenSource();
		const result = window.showQuickPick(data, undefined, source.token);
		source.cancel();
		const value_1 = await result;
		assert.equal(value_1, undefined);
	});
開發者ID:joelday,項目名稱:vscode,代碼行數:12,代碼來源:window.test.ts

示例3: it

  it('Should notify cancellation', async () => {
    const observable = new ReplaySubject<number | undefined>();
    observable.next(undefined);
    const cancellationTokenSource = new CancellationTokenSource();
    cancellationTokenSource.cancel();

    const notificationService = NotificationService.getInstance();
    await notificationService.reportExecutionStatus(
      'mock command',
      observable,
      cancellationTokenSource.token
    );

    assert.calledOnce(mShow);
    assert.notCalled(mShowInformation);
    assert.calledWith(mShowWarningMessage, 'mock command was canceled');
    assert.notCalled(mShowErrorMessage);
  });
開發者ID:nertofiveone,項目名稱:salesforcedx-vscode,代碼行數:18,代碼來源:index.test.ts

示例4: show

    static async show(
        stash: GitStash,
        mode: 'list' | 'apply',
        progressCancellation: CancellationTokenSource,
        goBackCommand?: CommandQuickPickItem,
        currentCommand?: CommandQuickPickItem
    ): Promise<CommitQuickPickItem<GitStashCommit> | CommandQuickPickItem | undefined> {
        const items = ((stash &&
            Array.from(Iterables.map(stash.commits.values(), c => new CommitQuickPickItem<GitStashCommit>(c)))) ||
            []) as (CommitQuickPickItem<GitStashCommit> | CommandQuickPickItem)[];

        if (mode === 'list') {
            const commandArgs: StashSaveCommandArgs = {
                goBackCommand: currentCommand
            };
            items.splice(
                0,
                0,
                new CommandQuickPickItem(
                    {
                        label: '$(plus) Stash Changes',
                        description: `${Strings.pad(GlyphChars.Dash, 2, 3)} stashes all changes`
                    },
                    Commands.StashSave,
                    [commandArgs]
                )
            );
        }

        if (goBackCommand) {
            items.splice(0, 0, goBackCommand);
        }

        if (progressCancellation.token.isCancellationRequested) return undefined;

        const scope = await Container.keyboard.beginScope({ left: goBackCommand });

        progressCancellation.cancel();

        const pick = await window.showQuickPick(items, {
            matchOnDescription: true,
            placeHolder:
                mode === 'apply'
                    ? `Apply stashed changes to your working tree${GlyphChars.Ellipsis}`
                    : `stashed changes ${GlyphChars.Dash} search by message, filename, or commit id`,
            ignoreFocusOut: getQuickPickIgnoreFocusOut()
            // onDidSelectItem: (item: QuickPickItem) => {
            //     scope.setKeyCommand('right', item);
            // }
        });

        await scope.dispose();

        return pick;
    }
開發者ID:chrisleaman,項目名稱:vscode-gitlens,代碼行數:55,代碼來源:stashListQuickPick.ts

示例5: show

    static async show(
        log: GitLog | undefined,
        placeHolder: string,
        progressCancellation: CancellationTokenSource,
        options: {
            goBackCommand?: CommandQuickPickItem;
            showAllCommand?: CommandQuickPickItem;
            showInViewCommand?: CommandQuickPickItem;
        }
    ): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> {
        const items = ((log && [...Iterables.map(log.commits.values(), c => new CommitQuickPickItem(c))]) || [
            new MessageQuickPickItem('No results found')
        ]) as (CommitQuickPickItem | CommandQuickPickItem)[];

        if (options.showInViewCommand !== undefined) {
            items.splice(0, 0, options.showInViewCommand);
        }

        if (options.showAllCommand !== undefined) {
            items.splice(0, 0, options.showAllCommand);
        }

        if (options.goBackCommand !== undefined) {
            items.splice(0, 0, options.goBackCommand);
        }

        if (progressCancellation.token.isCancellationRequested) return undefined;

        const scope = await Container.keyboard.beginScope({ left: options.goBackCommand });

        progressCancellation.cancel();

        const pick = await window.showQuickPick(items, {
            matchOnDescription: true,
            placeHolder: placeHolder,
            ignoreFocusOut: getQuickPickIgnoreFocusOut()
            // onDidSelectItem: (item: QuickPickItem) => {
            //     scope.setKeyCommand('right', item);
            // }
        });

        await scope.dispose();

        return pick;
    }
開發者ID:chrisleaman,項目名稱:vscode-gitlens,代碼行數:45,代碼來源:commitsQuickPick.ts

示例6: test

    test('Kill', done => {
        const def = createDeferred<any>();
        const output: string[] = [];
        function handleOutput(data: string) {
            output.push(data);
        }
        const cancellation = new vscode.CancellationTokenSource();
        execPythonFile('python', ['-c', 'import sys\nprint(1)\nsys.__stdout__.flush()\nimport time\ntime.sleep(5)\nprint(2)'], __dirname, false, handleOutput, cancellation.token).then(() => {
            def.reject('Should not have completed');
        }).catch(()=>{
            def.resolve();
        });

        setTimeout(() => {
            cancellation.cancel();
        }, 1000);

        def.promise.then(done).catch(done);
    });
開發者ID:walkoncross,項目名稱:pythonVSCode,代碼行數:19,代碼來源:extension.common.test.ts

示例7: _showQuickPickProgress

async function _showQuickPickProgress(message: string, cancellation: CancellationTokenSource, mapping?: KeyMapping) {
    const scope = mapping && (await Container.keyboard.beginScope(mapping));

    try {
        await window.showQuickPick(
            _getInfiniteCancellablePromise(cancellation),
            {
                placeHolder: message,
                ignoreFocusOut: getQuickPickIgnoreFocusOut()
            },
            cancellation.token
        );
    }
    catch (ex) {
        // Not sure why this throws
    }
    finally {
        cancellation.cancel();
        scope && scope.dispose();
    }
}
開發者ID:chrisleaman,項目名稱:vscode-gitlens,代碼行數:21,代碼來源:commonQuickPicks.ts

示例8: 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

示例9:

 items = items.then(itms => {
     if (itms.length <= 1) {
         autoPick = itms[0];
         cancellation.cancel();
     }
     return itms;
 });
開發者ID:chrisleaman,項目名稱:vscode-gitlens,代碼行數:7,代碼來源:referencesQuickPick.ts

示例10: cancelCommandExecution

export function cancelCommandExecution() {
  if (cancellationTokenSource) {
    cancellationTokenSource.cancel();
    cancellationTokenSource = undefined;
    resetStatusBarItem();
    if (statusTimer) {
      clearInterval(statusTimer);
      statusTimer = undefined;
    }
  }
}
開發者ID:nertofiveone,項目名稱:salesforcedx-vscode,代碼行數:11,代碼來源:statusBar.ts


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