taking care of connection during creation

This commit is contained in:
martin 2020-11-11 18:11:37 +01:00
parent 46da72ab64
commit e93e50c43c
3 changed files with 17 additions and 6 deletions

View File

@ -124,6 +124,8 @@ const main = async function () {
return; return;
} }
await dispatcher.ready.waitFor(value => value);
const sleep = promisify(setTimeout); const sleep = promisify(setTimeout);
await sleep(1000); await sleep(1000);

View File

@ -26,12 +26,19 @@ export function getLinkedDispatcher(options: INopeRpcDispatcherOptions) {
const dispatcher = getDispatcher(options); const dispatcher = getDispatcher(options);
// Iterate over the Functions // If the Dispatcher has been connected, register all functions.
for (const [uri, settings] of container.instance.entries()) { dispatcher.ready.waitFor(value => value).then(() => {
dispatcher.registerFunction(settings.callback, { if (dispatcher.ready.getContent()){
id: uri // Iterate over the Functions
}); for (const [uri, settings] of container.instance.entries()) {
} dispatcher.registerFunction(settings.callback, {
id: uri
});
}
} else {
console.log('Failed')
}
});
return dispatcher; return dispatcher;
} }

View File

@ -24,6 +24,8 @@ export type IValidPromise<T> = Promise<T> | INopePromise<T>;
* @interface INopeDispatcher * @interface INopeDispatcher
*/ */
export interface INopeDispatcher { export interface INopeDispatcher {
readonly ready: INopeObservable<boolean>;
/** /**
* ID of the Dispatcher * ID of the Dispatcher