UNPKG

@eclipse-emfcloud/model-service-theia

Version:
56 lines 2.73 kB
"use strict"; // ***************************************************************************** // Copyright (C) 2024 STMicroelectronics. // // 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: MIT License which is // available at https://opensource.org/licenses/MIT. // // SPDX-License-Identifier: EPL-2.0 OR MIT // ***************************************************************************** Object.defineProperty(exports, "__esModule", { value: true }); exports.bindFrontendModelHubProvider = bindFrontendModelHubProvider; const common_1 = require("../common"); const model_hub_tracker_1 = require("../common/model-hub-tracker"); const frontend_model_hub_1 = require("./frontend-model-hub"); /** * Bind the `FrontendModelHubProvider` service in _Inversify_. */ function bindFrontendModelHubProvider(bind) { bind(frontend_model_hub_1.FrontendModelHubProvider).toProvider(({ container }) => { const tracker = container.get(model_hub_tracker_1.ModelHubTracker); return async (context) => { // Ensure the initialization of the RPC Protocol so that we may receive // notifications from the backend container.get(common_1.ModelHubProtocol); const child = container.createChild(); child.bind(frontend_model_hub_1.FrontendModelHubImpl).toSelf(); child.bind(frontend_model_hub_1.FrontendModelHubContext).toConstantValue(context); if (tracker.isModelHubAvailable(context)) { // Easy case: it's already available in the backend return child.get(frontend_model_hub_1.FrontendModelHubImpl); } // Need to wait for it to become available in the backend const sub = tracker.trackModelHubs(); const result = new Promise((resolve, reject) => { sub.onModelHubCreated = (createdContext) => { if (createdContext === context) { try { resolve(child.get(frontend_model_hub_1.FrontendModelHubImpl)); } catch (error) { reject(error); } } }; }); return (0, common_1.timeout)(result).finally(() => sub.close()); }; }); } //# sourceMappingURL=frontend-model-hub-provider.js.map