From e93e50c43c272460250e1db245a1eddb5a919908 Mon Sep 17 00:00:00 2001 From: martin Date: Wed, 11 Nov 2020 18:11:37 +0100 Subject: [PATCH] taking care of connection during creation --- lib/cli/runNopeBackend.ts | 2 ++ lib/dispatcher/getLinkedDispatcher.ts | 19 +++++++++++++------ lib/types/nope/nopeDispatcher.interface.ts | 2 ++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/cli/runNopeBackend.ts b/lib/cli/runNopeBackend.ts index ac88295..486aa57 100644 --- a/lib/cli/runNopeBackend.ts +++ b/lib/cli/runNopeBackend.ts @@ -124,6 +124,8 @@ const main = async function () { return; } + await dispatcher.ready.waitFor(value => value); + const sleep = promisify(setTimeout); await sleep(1000); diff --git a/lib/dispatcher/getLinkedDispatcher.ts b/lib/dispatcher/getLinkedDispatcher.ts index 8553787..245736a 100644 --- a/lib/dispatcher/getLinkedDispatcher.ts +++ b/lib/dispatcher/getLinkedDispatcher.ts @@ -26,12 +26,19 @@ export function getLinkedDispatcher(options: INopeRpcDispatcherOptions) { const dispatcher = getDispatcher(options); - // Iterate over the Functions - for (const [uri, settings] of container.instance.entries()) { - dispatcher.registerFunction(settings.callback, { - id: uri - }); - } + // 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; } diff --git a/lib/types/nope/nopeDispatcher.interface.ts b/lib/types/nope/nopeDispatcher.interface.ts index 720887a..b8bb179 100644 --- a/lib/types/nope/nopeDispatcher.interface.ts +++ b/lib/types/nope/nopeDispatcher.interface.ts @@ -24,6 +24,8 @@ export type IValidPromise = Promise | INopePromise; * @interface INopeDispatcher */ export interface INopeDispatcher { + + readonly ready: INopeObservable; /** * ID of the Dispatcher