/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45/**6* Given a function, returns a function that is only calling that function once.7*/8export function createSingleCallFunction<T extends Function>(this: unknown, fn: T, fnDidRunCallback?: () => void): T {9const _this = this;10let didCall = false;11let result: unknown;1213return function () {14if (didCall) {15return result;16}1718didCall = true;19if (fnDidRunCallback) {20try {21result = fn.apply(_this, arguments);22} finally {23fnDidRunCallback();24}25} else {26result = fn.apply(_this, arguments);27}2829return result;30} as unknown as T;31}323334