From 8284845262d22e89404d1ca29e22e8b2bba744de Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Fri, 18 Oct 2024 08:54:12 +0200 Subject: [PATCH] fix: worker tries to open websocket before sending any request --- packages/worker-api/src/sendRequest.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/worker-api/src/sendRequest.ts b/packages/worker-api/src/sendRequest.ts index 17f9145f..4df40a29 100644 --- a/packages/worker-api/src/sendRequest.ts +++ b/packages/worker-api/src/sendRequest.ts @@ -8,7 +8,11 @@ import { import { Request } from './interface.js'; import type {ShardIdentifier, IntegriteeTrustedCallSigned} from "@encointer/types"; -export const sendWorkerRequest = (self: IWorker, clientRequest: any, parserType: string, options?: RequestOptions): Promise =>{ +export const sendWorkerRequest = async (self: IWorker, clientRequest: any, parserType: string, options?: RequestOptions): Promise =>{ + if( !self.isOpened ) { + await self.open(); + } + const requestId = self.rqStack.push(parserType) + self.rsCount; const timeout = options && options.timeout ? options.timeout : undefined; return self.sendRequest( @@ -20,9 +24,6 @@ export const sendWorkerRequest = (self: IWorker, clientRequest: any, parserType: } export const callGetter = async (self: IWorker, workerMethod: WorkerMethod, _args: RequestArgs, requestOptions?: RequestOptions): Promise => { - if( !self.isOpened ) { - await self.open(); - } const [getterType, method, parser] = workerMethod; let result: Promise; let parserType: string = requestOptions?.debug ? 'raw': parser; @@ -37,10 +38,6 @@ export const callGetter = async (self: IWorker, workerMethod: WorkerMethod, _ } export const sendTrustedCall = async (self: IWorker, call: IntegriteeTrustedCallSigned, shard: ShardIdentifier, direct: boolean, parser: string, options: RequestOptions = {} as RequestOptions): Promise => { - if( !self.isOpened ) { - await self.open(); - } - let result: Promise; let parserType: string = options.debug ? 'raw': parser;