nope/lib/dispatcher/getLinkedDispatcher.ts

46 lines
1.3 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
* @modify date 2020-11-11 16:38:47
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
// If the Dispatcher has been connected, register all functions.
dispatcher.ready.waitFor(value => value).then(() => {
if (dispatcher.ready.getContent()){
// Iterate over the Functions
for (const [uri, settings] of container.instance.entries()) {
dispatcher.registerFunction(settings.callback, {
id: uri
});
}
} else {
console.log('Failed')
}
});
2020-09-10 16:21:01 +00:00
2020-08-25 22:11:26 +00:00
return dispatcher;
}