How to use the @theia/core/lib/common/promise-util.Deferred 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 / terminal / src / browser / terminal-widget-impl.ts View on Github external
protected connectTerminalProcess(): void {
        if (typeof this.terminalId !== 'number') {
            return;
        }
        this.toDisposeOnConnect.dispose();
        this.toDispose.push(this.toDisposeOnConnect);
        this.term.reset();
        const waitForConnection = this.waitForConnection = new Deferred();
        this.webSocketConnectionProvider.listen({
            path: `${terminalsPath}/${this.terminalId}`,
            onConnection: connection => {
                connection.onNotification('onData', (data: string) => this.write(data));

                // Excludes the device status code emitted by Xterm.js
                const sendData = (data?: string) => {
                    if (data && !this.deviceStatusCodes.has(data)) {
                        return connection.sendRequest('write', data);
                    }
                };

                const disposable = this.term.onData(sendData);
                connection.onDispose(() => disposable.dispose());

                this.toDisposeOnConnect.push(connection);
github eclipse-theia / theia / packages / plugin-ext / src / main / browser / storage-path-service.ts View on Github external
async updateStoragePath(roots: FileStat[]): Promise {
        const workspace = this.workspaceService.workspace;
         if (!workspace) {
             this.path = undefined;
         }

         const newPath = await this.pluginPathsService.provideHostStoragePath(workspace, roots);
         if (this.path !== newPath) {
             this.path = newPath;
             this.pathDeferred.resolve(this.path);
             this.pathDeferred = new Deferred();
             this.pathDeferred.resolve(this.path);
             this.onStoragePathChangeEmitter.fire(this.path);
         }
    }
github eclipse-theia / theia / packages / git / src / node / git-repository-watcher.ts View on Github external
sync(): Promise {
        if (this.idle) {
            if (this.interruptIdle) {
                this.interruptIdle();
            }
        } else {
            this.skipNextIdle = true;
        }
        const result = new Deferred();
        this.syncWorkPromises.push(result);
        return result.promise;
    }
github eclipse-theia / theia / packages / terminal / src / browser / default-terminal-client.ts View on Github external
protected createConnection(): void {
        if (!IBaseTerminalServer.validateId(this.terminalId)) {
            return;
        }

        this.toDisposeOnConnect.dispose();
        this.toDispose.push(this.toDisposeOnConnect);
        this.widget.reset();

        const waitForConnection = this.waitForConnection = new Deferred();
        this.webSocketConnectionProvider.listen({
            path: `${terminalsPath}/${this.terminalId}`,
            onConnection: connection => {
                connection.onNotification('onData', (data: string) => this.widget.write(data));

                this.toDisposeOnConnect.push(this.widget.onUserInput(data => data && connection.sendRequest('write', data)));
                this.toDisposeOnConnect.push(connection);

                connection.listen();
                if (waitForConnection) {
                    waitForConnection.resolve(connection);
                }
            }
        }, { reconnecting: false });
    }
github eclipse-theia / theia / packages / messages / src / browser / notifications-manager.ts View on Github external
if (!notification) {
            const message = this.renderMessage(plainMessage.text);
            const type = this.toNotificationType(plainMessage.type);
            const actions = Array.from(new Set(plainMessage.actions));
            const source = plainMessage.source;
            const expandable = this.isExpandable(message, source, actions);
            const collapsed = expandable;
            notification = { messageId, message, type, actions, expandable, collapsed };
            this.notifications.set(messageId, notification);

            notification.progress = 0;
            cancellationToken.onCancellationRequested(() => {
                this.accept(messageId, ProgressMessage.Cancel);
            });
        }
        const result = this.deferredResults.get(messageId) || new Deferred();
        this.deferredResults.set(messageId, result);

        if (!this.centerVisible) {
            this.toasts.set(messageId, notification);
            this.setVisibilityState('toasts');
        }
        this.fireUpdatedEvent();
        return result.promise;
    }
github eclipse-theia / theia / packages / workspace / src / node / default-workspace-server.ts View on Github external
async setMostRecentlyUsedWorkspace(uri: string): Promise {
        this.root = new Deferred();
        const listUri: string[] = [];
        const oldListUri = await this.getRecentWorkspaces();
        listUri.push(uri);
        if (oldListUri) {
            oldListUri.forEach(element => {
                if (element !== uri && element.length > 0) {
                    listUri.push(element);
                }
            });
        }
        this.root.resolve(uri);
        this.writeToUserHome({
            recentRoots: listUri
        });
    }