Skip to content

Commit

Permalink
fix: worker tries to open websocket before sending any request (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
clangenb authored Oct 18, 2024
1 parent b91e972 commit b9ef8c4
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions packages/worker-api/src/sendRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> =>{
export const sendWorkerRequest = async (self: IWorker, clientRequest: any, parserType: string, options?: RequestOptions): Promise<any> =>{
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(
Expand All @@ -20,9 +24,6 @@ export const sendWorkerRequest = (self: IWorker, clientRequest: any, parserType:
}

export const callGetter = async <T>(self: IWorker, workerMethod: WorkerMethod, _args: RequestArgs, requestOptions?: RequestOptions): Promise<T> => {
if( !self.isOpened ) {
await self.open();
}
const [getterType, method, parser] = workerMethod;
let result: Promise<any>;
let parserType: string = requestOptions?.debug ? 'raw': parser;
Expand All @@ -37,10 +38,6 @@ export const callGetter = async <T>(self: IWorker, workerMethod: WorkerMethod, _
}

export const sendTrustedCall = async <T>(self: IWorker, call: IntegriteeTrustedCallSigned, shard: ShardIdentifier, direct: boolean, parser: string, options: RequestOptions = {} as RequestOptions): Promise<T> => {
if( !self.isOpened ) {
await self.open();
}

let result: Promise<any>;
let parserType: string = options.debug ? 'raw': parser;

Expand Down

0 comments on commit b9ef8c4

Please sign in to comment.