How to use the @theia/core.CancellationTokenSource function in @theia/core

To help you get started, we’ve selected a few @theia/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eclipse-theia / theia / packages / plugin-ext / src / hosted / browser / hosted-plugin.ts View on Github external
if (/^workspaceContains:/.test(activationEvent)) {
                const fileNameOrGlob = activationEvent.substr('workspaceContains:'.length);
                if (fileNameOrGlob.indexOf('*') >= 0 || fileNameOrGlob.indexOf('?') >= 0) {
                    includePatterns.push(fileNameOrGlob);
                } else {
                    paths.push(fileNameOrGlob);
                }
            }
        }
        const activatePlugin = () => manager.$activateByEvent(`onPlugin:${plugin.metadata.model.id}`);
        const promises: Promise[] = [];
        if (paths.length) {
            promises.push(this.workspaceService.containsSome(paths));
        }
        if (includePatterns.length) {
            const tokenSource = new CancellationTokenSource();
            const searchTimeout = setTimeout(() => {
                tokenSource.cancel();
                // activate eagerly if took to long to search
                activatePlugin();
            }, 7000);
            promises.push((async () => {
                try {
                    const result = await this.fileSearchService.find('', {
                        rootUris: this.workspaceService.tryGetRoots().map(r => r.uri),
                        includePatterns,
                        limit: 1
                    }, tokenSource.token);
                    return result.length > 0;
                } catch (e) {
                    if (!isCancelled(e)) {
                        console.error(e);
github eclipse-theia / theia / packages / monaco / src / browser / monaco-editor-model.ts View on Github external
protected cancelSave(): CancellationToken {
        this.saveCancellationTokenSource.cancel();
        this.saveCancellationTokenSource = new CancellationTokenSource();
        return this.saveCancellationTokenSource.token;
    }
github eclipse-theia / theia / packages / languages / src / browser / workspace-symbols.ts View on Github external
async onType(lookFor: string, acceptor: (items: QuickOpenItem[]) => void): Promise {
        if (this.languages.workspaceSymbolProviders) {
            this.cancellationSource.cancel();
            const newCancellationSource = new CancellationTokenSource();
            this.cancellationSource = newCancellationSource;

            const param: WorkspaceSymbolParams = {
                query: lookFor,
            };

            const items: QuickOpenItem[] = [];

            for (const provider of this.languages.workspaceSymbolProviders) {
                provider.provideWorkspaceSymbols(param, newCancellationSource.token).then(symbols => {
                    if (symbols && !newCancellationSource.token.isCancellationRequested) {
                        for (const symbol of symbols) {
                            items.push(this.createItem(symbol));
                        }
                        acceptor(items);
                    }
github eclipse-theia / theia / packages / extension-manager / src / node / application-project.ts View on Github external
async scheduleInstall(): Promise {
        if (this.installationTokenSource) {
            this.installationTokenSource.cancel();
        }
        this.installationTokenSource = new CancellationTokenSource();
        const token = this.installationTokenSource.token;
        this.installed = this.installed.then(() => this.install(token));
        await this.installed;
    }
github eclipse-theia / theia / packages / git / src / browser / git-repository-tracker.ts View on Github external
protected updateStatus = debounce(async (): Promise => {
        this.toDispose.dispose();
        const tokenSource = new CancellationTokenSource();
        this.toDispose.push(Disposable.create(() => tokenSource.cancel()));
        const token = tokenSource.token;
        const source = this.selectedRepository;
        if (source) {
            const status = await this.git.status(source);
            this.setStatus({ source, status }, token);
            this.toDispose.push(this.gitWatcher.onGitEvent(event => {
                if (event.source.localUri === source.localUri) {
                    this.setStatus(event, token);
                }
            }));
            this.toDispose.push(await this.gitWatcher.watchGitChanges(source));
        } else {
            this.setStatus(undefined, token);
        }
    }, 50);
github eclipse-theia / theia / packages / search-in-workspace / src / browser / search-in-workspace-result-tree-widget.tsx View on Github external
async search(searchTerm: string, searchOptions: SearchInWorkspaceOptions): Promise {
        this.searchTerm = searchTerm;
        const collapseValue: string = this.searchInWorkspacePreferences['search.collapseResults'];
        this.resultTree.clear();
        this.cancelIndicator.cancel();
        this.cancelIndicator = new CancellationTokenSource();
        const token = this.cancelIndicator.token;
        if (searchTerm === '') {
            this.refreshModelChildren();
            return;
        }
        const progress = await this.progressService.showProgress({ text: `search: ${searchTerm}`, options: { location: 'search' } });
        const searchId = await this.searchService.search(searchTerm, {
            onResult: (aSearchId: number, result: SearchInWorkspaceResult) => {
                if (token.isCancellationRequested || aSearchId !== searchId) {
                    return;
                }
                const { path } = this.filenameAndPath(result.root, result.fileUri);
                const tree = this.resultTree;
                const rootFolderNode = tree.get(result.root);

                if (rootFolderNode) {
github eclipse-theia / theia / packages / file-search / src / node / file-search-service-impl.ts View on Github external
async find(searchPattern: string, options: FileSearchService.Options, clientToken?: CancellationToken): Promise {
        const cancellationSource = new CancellationTokenSource();
        if (clientToken) {
            clientToken.onCancellationRequested(() => cancellationSource.cancel());
        }
        const token = cancellationSource.token;
        const opts = {
            fuzzyMatch: true,
            limit: Number.MAX_SAFE_INTEGER,
            useGitIgnore: true,
            ...options
        };

        const roots: FileSearchService.RootOptions = options.rootOptions || {};
        if (options.rootUris) {
            for (const rootUri of options.rootUris) {
                if (!roots[rootUri]) {
                    roots[rootUri] = {};
github eclipse-theia / theia / packages / monaco / src / browser / monaco-editor-model.ts View on Github external
protected cancelSync(): CancellationToken {
        this.syncCancellationTokenSource.cancel();
        this.syncCancellationTokenSource = new CancellationTokenSource();
        return this.syncCancellationTokenSource.token;
    }