nope/lib/dispatcher/getLinkedDispatcher.ts

39 lines
1.0 KiB
TypeScript
Raw Normal View History

2020-08-25 22:11:26 +00:00
/**
* @author Martin Karkowski
* @email m.karkowski@zema.de
* @create date 2020-08-25 23:27:28
2020-11-07 00:45:20 +00:00
* @modify date 2020-11-07 00:36:27
2020-08-25 22:11:26 +00:00
* @desc [description]
*/
2020-11-06 13:18:10 +00:00
import { IExportFunctionToDispatcherParameters } from "../decorators/dispatcherDecorators";
2020-08-25 22:11:26 +00:00
import { getSingleton } from "../helpers/singletonMethod";
2020-11-09 08:46:06 +00:00
import { INopeRpcDispatcherOptions } from "../types/nope/nopeCommunication.interface";
2020-11-06 13:18:10 +00:00
import { getDispatcher } from "./getDispatcher";
2020-08-25 22:11:26 +00:00
/**
* Returns a Dispatcher.
* @param options
2020-08-25 22:11:26 +00:00
*/
2020-10-13 13:18:25 +00:00
export function getLinkedDispatcher(options: INopeRpcDispatcherOptions) {
2020-09-10 16:21:01 +00:00
const container = getSingleton('nopeBackendDispatcher.container', () => {
2020-11-06 13:18:10 +00:00
return new Map<string, {
uri: string,
callback: (...args) => Promise<any>,
options: IExportFunctionToDispatcherParameters
}>()
2020-08-25 22:11:26 +00:00
});
2020-11-06 13:18:10 +00:00
const dispatcher = getDispatcher(options);
2020-08-25 22:11:26 +00:00
2020-09-10 16:21:01 +00:00
// Iterate over the Functions
2020-11-06 13:18:10 +00:00
for (const [uri, settings] of container.instance.entries()) {
2020-09-10 16:21:01 +00:00
dispatcher.registerFunction(settings.callback, {
id: uri
});
}
2020-08-25 22:11:26 +00:00
return dispatcher;
}