UNPKG

@eclipse-glsp/protocol

Version:

The protocol definition for client-server communication in GLSP

79 lines 3.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Emitter = exports.Event = void 0; /******************************************************************************** * Copyright (c) 2023-2024 EclipseSource and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. * * This Source Code may also be made available under the following Secondary * Licenses when the conditions for such availability set forth in the Eclipse * Public License v. 2.0 are satisfied: GNU General Public License, version 2 * with the GNU Classpath Exception which is available at * https://www.gnu.org/software/classpath/license.html. * * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ const jsonrpc = require("vscode-jsonrpc"); var Event; (function (Event) { /** * Utility function to register a one-time listener for an event. The listener will be disposed * automatically after the next event is fired. * @param event The event to listen to * @param listener The listener function that will be called when the event happens. * @param thisArgs The 'this' which will be used when calling the event listener. * @param disposables An array to which the {@link Disposable} for removing the listener will be added. * @returns a {@link Disposable} to remove the listener again. */ function once(event, listener, thisArgs, disposables) { const toDispose = event(e => { listener(e); toDispose.dispose(); }, thisArgs, disposables); return toDispose; } Event.once = once; /** * Utility function to wait for an event to happen. The function will return a promise that will be resolved * when the event is fired. Optionally a predicate can be provided that will be used to filter the event. * If a predicate is provided, the promise will only be resolved when the predicate returns true. * The underlying listener will be disposed automatically when the promise is resolved. * @param event The event to listen to * @param predicate An optional predicate that will be used to filter the event * @returns a promise that will be resolved when the event is fired (and the optional predicate matches) */ function waitUntil(event, predicate) { return new Promise(resolve => { const toDispose = event(e => { if (!predicate || predicate(e)) { resolve(e); toDispose.dispose(); } }); }); } Event.waitUntil = waitUntil; })(Event || (exports.Event = Event = {})); class Emitter extends jsonrpc.Emitter { constructor(options = {}) { super(options); } /** * The even that is managed by this emitter. * Intended for the public to allow to subscribe to the emitter`s events. */ get event() { return super.event; } /** * Fires and event and notifies all registered listeners */ fire(event) { super.fire(event); } } exports.Emitter = Emitter; //# sourceMappingURL=event.js.map