typescript-language-server
Version:
Language Server Protocol (LSP) implementation for TypeScript using tsserver
47 lines • 1.72 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/*
* Copyright (C) 2022 TypeFox and others.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/
import { ServerResponse } from './requests.js';
export class CallbackMap {
constructor() {
this._callbacks = new Map();
this._asyncCallbacks = new Map();
}
destroy(cause) {
const cancellation = new ServerResponse.Cancelled(cause);
for (const callback of this._callbacks.values()) {
callback.onSuccess(cancellation);
}
this._callbacks.clear();
for (const callback of this._asyncCallbacks.values()) {
callback.onSuccess(cancellation);
}
this._asyncCallbacks.clear();
}
add(seq, callback, isAsync) {
if (isAsync) {
this._asyncCallbacks.set(seq, callback);
}
else {
this._callbacks.set(seq, callback);
}
}
fetch(seq) {
const callback = this._callbacks.get(seq) || this._asyncCallbacks.get(seq);
this.delete(seq);
return callback;
}
delete(seq) {
if (!this._callbacks.delete(seq)) {
this._asyncCallbacks.delete(seq);
}
}
}
//# sourceMappingURL=callbackMap.js.map