/** * @author Martin Karkowski * @email m.karkowski@zema.de * @create date 2020-08-25 23:27:28 * @modify date 2020-11-14 17:43:41 * @desc [description] */ import { IExportFunctionToDispatcherParameters } from "../decorators/dispatcherDecorators"; import { getSingleton } from "../helpers/singletonMethod"; import { INopeDispatcherOptions } from "../types/nope/nopeCommunication.interface"; import { getDispatcher } from "./getDispatcher"; /** * Returns a Dispatcher. * @param options */ export function getLinkedDispatcher(options: INopeDispatcherOptions) { // Create the Dispatcher Instance. const dispatcher = getDispatcher(options); // Define a Container, which contains all functions. const container = getSingleton("nopeBackendDispatcher.container", () => { return new Map Promise, options: IExportFunctionToDispatcherParameters }>(); }); // If the Dispatcher has been connected, register all functions. dispatcher.ready.waitFor(value => value === true).then(() => { if (dispatcher.ready.getContent()) { // Iterate over the Functions for (const [uri, settings] of container.instance.entries()) { dispatcher.registerFunction(settings.callback, { id: uri }); } } else { // Failed to Setup the Container. } }); return dispatcher; }