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;
}
await dispatcher.ready.waitFor(value => value);
const sleep = promisify(setTimeout);
await sleep(1000);

View File

@ -26,12 +26,19 @@ export function getLinkedDispatcher(options: INopeRpcDispatcherOptions) {
const dispatcher = getDispatcher(options);
// 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')
}
});
return dispatcher;
}

View File

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